How to get the JPA generated SQL query?

前端 未结 6 1218
北荒
北荒 2020-12-28 17:50

I use JPA specification and Hibernate as my vendor. I need somehow to take the generated SQL Query which is sent to the the DB (printed to the sysout) and save it as a simpl

6条回答
  •  太阳男子
    2020-12-28 18:07

    Create a bean like this.

    @Bean
    public JpaVendorAdapter jpaVendorAdapter(){
        HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
        jpaVendorAdapter.setGenerateDdl(true);
        jpaVendorAdapter.setShowSql(true);
    
        return jpaVendorAdapter;
    }
    

    If you're using Spring Boot add it somewhere to your @Configuration.

    The logs created from this are executable in MySQL workbench. You stated that you are using JPA and Hibernate. There's no other way except if the database you support are supported by JPA. In that case there is an AbstractJpaVendorAdapter that you can implement.

提交回复
热议问题