Hibernate 4 Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

后端 未结 12 1725
青春惊慌失措
青春惊慌失措 2021-01-17 14:25

I am using Hibernate latest version 4.3.5.Final.

My hibernate.cfg.xml file content:



        
相关标签:
12条回答
  • 2021-01-17 14:41

    Finally able to fix the issue, the issue is with the way SessionFactory is getting created.

    For a starter, official document is the first place to go and I must say that Hibernate official documentation seems to be not update with latest version changes.

    Fix is to apply the configuration settings to StandardServiceRegistryBuilder instance.

    // Create the SessionFactory from hibernate.cfg.xml
    Configuration configuration = new Configuration();
    configuration.configure("hibernate.cfg.xml");
    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySettings(configuration.getProperties()).build();
    SessionFactory sessionFactory = configuration
            .buildSessionFactory(serviceRegistry);
    

    Please refer my blog post here for more details.

    0 讨论(0)
  • 2021-01-17 14:41

    In my case I ran the configuration routine twice. I had automatic configuration (ie config from xml in resources) in one method, then I implemented a configuration by setting properties in another method but I forgot to bypass the former. As soon as I did, the error gone.

    0 讨论(0)
  • 2021-01-17 14:44

    You cal also fix the issue by creating the sesisonFactory this way.

    SessionFactory sessionFactory = new
    Configuration().configure().buildSessionFactory(
    new StandardServiceRegistryBuilder().applySettings(new
    Configuration().configure().getProperties()).build());
    
    0 讨论(0)
  • 2021-01-17 14:48

    I had the exactly 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

    0 讨论(0)
  • 2021-01-17 14:49

    The same problem occurred to me with the mysql service running, correct credentials, but the database name was misspelled, so basically the database did not exist.

    0 讨论(0)
  • 2021-01-17 14:49

    This will be OK

    Configuration cfg = new Configuration().configure();
    
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
            .applySettings(cfg.getProperties()).build();
    
    SessionFactory sf = cfg.buildSessionFactory(serviceRegistry);
    
    Session session = sf.openSession();
    
    0 讨论(0)
提交回复
热议问题