Connection cannot be null when 'hibernate.dialect' not set

后端 未结 15 1640
悲&欢浪女
悲&欢浪女 2020-12-16 11:12

having more issues with seting up hibernate with spring3. this time it is saying that connection is nul as the dialect is not set which it is on my hibernate.cfg.xml file.

相关标签:
15条回答
  • 2020-12-16 11:12

    I think its the problem of not loading your hibernate.cfg.xml file in your application.

    I too got the same problem. I have tried with the following code in my project:

    Configuration cfg = new Configuration();
    cfg.configure("hibernate.cfg.xml");
    

    Then it has worked fine. Hope this will help.

    0 讨论(0)
  • 2020-12-16 11:13

    I had this error with JPA, then I just added this line to application.properties:

    spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
    

    based on this post: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

    0 讨论(0)
  • 2020-12-16 11:15

    I you are using hibernate and InnoDB why don't you set the hibernate.dialect to org.hibernate.dialect.MySQL5 or org.hibernate.dialect.MySQL.

    and the connection property to hibernate.connection.url.

    0 讨论(0)
  • 2020-12-16 11:15

    I think the error cased by unloading hibernate.cfg.xml file after you have created the Configuration Object like this:

    Configuration config = new Configuration();
    config.configure("hibernate.cfg.xml");
    
    0 讨论(0)
  • 2020-12-16 11:17

    Added the following in persistence.xml file,

    <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
    
    0 讨论(0)
  • 2020-12-16 11:23

    Creation of ServiceRegistry instance separately and pass it to buildSessionFactory may cause this error. Try to create SessionFactory instance as follows:

    private static SessionFactory factory;
    factory = cfg.buildSessionFactory(
              new ServiceRegistryBuilder().applySettings(cfg.getProperties())
             .buildServiceRegistry());
    
    0 讨论(0)
提交回复
热议问题