Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
2017-03-30 15:24
573 查看
错误信息:
Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at com.yangwan.test.MainTest.createSessionV3(MainTest.java:77)
at com.yangwan.test.MainTest.main(MainTest.java:102)
右上方信息可以定位到出错代码:
SessionFactory sessionFactory = configuration.buildSessionFactory(sr);--->出现错误。
解决方法:
Hibernate v4以后就已经废弃了利用ServiceRegister来创建SessionFactory了。所有创建SessionFactory的方法在Hibernate v4后就不适合了。
正确的SessionFactory创建代码:
Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:104)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:71)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:209)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at com.yangwan.test.MainTest.createSessionV3(MainTest.java:77)
at com.yangwan.test.MainTest.main(MainTest.java:102)
右上方信息可以定位到出错代码:
Configuration configuration = new Configuration().configure(); StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder(); ServiceRegistry sr = ssrb.build(); SessionFactory sessionFactory = configuration.buildSessionFactory(sr); Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); Person temp = new Person("xiaoxiao",22); try{ session.save(temp); transaction.commit(); }catch(Exception ex){ ex.printStackTrace(); transaction.rollback(); }finally{ session.close(); }
SessionFactory sessionFactory = configuration.buildSessionFactory(sr);--->出现错误。
解决方法:
Hibernate v4以后就已经废弃了利用ServiceRegister来创建SessionFactory了。所有创建SessionFactory的方法在Hibernate v4后就不适合了。
正确的SessionFactory创建代码:
Configuration cfg = new Configuration().configure(); StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build(); SessionFactory sessionFactory = cfg.buildSessionFactory(serviceRegistry);
相关文章推荐
- Hibernate4.3.x Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
- 创建SessionFactory出错Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
- [Hibernate]Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
- failed.org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hiber
- [Solved] HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’
- [Hibernate]Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
- Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dia
- ExceptionInInitialize Access to DialectResolutionInfo cannot be null when 'hibernate.dialect'not set
- Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set——【hibernate 日常错误】
- Connection cannot be null when 'hibernate.dialect' not set
- org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set .
- 异常记录001—hibernate 4.2.4 Final 测试出现Connection cannot be null when 'hibernate.dialect' not set
- Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot
- Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not
- Exception in thread "main" org.hibernate.HibernateException: Access to DialectResolutionInfo cannot
- Hibernate Connection cannot be null when 'hibernate.dialect' not set错误
- 马士兵的第一个hibernate程序(Connection cannot be null when 'hibernate.dialect' not set)
- hibernate第二篇 org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' no
- org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set