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

后端 未结 15 1641
悲&欢浪女
悲&欢浪女 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:24

    i think you are not configure hibernate.cfg.xml.

    Configuration configuration = new Configuration();
    configuration.configure("hibernate.cfg.xml");
    SessionFactory factory = configuration.buildSessionFactory();
    
    0 讨论(0)
  • 2020-12-16 11:24

    We were recently facing the same issue with one of our deployment, as we were also using hibernate and dialect is null is a vague error. I use was with connection string itself and did the changes below to make it work

    connectionUrl :- jdbc:mysql://127.0.0.1:3306/{{dbName}}?serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false

    Steps how did we solve it 1) We ran simple DB connection with JDBC driver that will gave the exception of time zone. 2) we found the issue with time zone and had to add more properties in connection string as show above. 3) We also added 2 other properties as still it was not working.

    Dialect is not set is vague to took lot of our time, I hope this helps.

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

    You did't post your session factory initialization code. But I guess this is the same problem with this one

    From Hibernate 4.3.2.Final, StandardServiceRegistryBuilder is introduced. Please follow this order to intialize, e.g.:

    Configuration configuration = new Configuration();
    configuration.configure("com/jeecourse/config/hibernate.cfg.xml");
    
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
            configuration.getProperties()).build();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    

    Please double check your code.

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

    I think you don't create the Configuration like below.

    Configuration conf = new Configuration().configure();
    

    Best

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

    I think your datasource-config.xml is not in classpath

    instead of having this file in WEB-INF/datasource-config.xml

    copy it to WEB-INF/classes/datasource-config.xml

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

    I had the the same problem and the issue was, that my computer was not entered in the pg_hba.conf of the postgres database that allows which Clients(IP-Adresses) are allowed to speak with the database.

    btw: Other users tells that the error raises too if they simply forget starting database service locally

    0 讨论(0)
提交回复
热议问题