Dialect not getting set in hibernate

泄露秘密 提交于 2019-12-05 16:12:43

Either your first or second line should work. The second way, with just "dialect" is the way shown in the Hibernate reference. If you're still getting that error, it suggests you may have something else going on. How are you building the SessionFactory? Are you sure it's finding your hibernate.cfg.xml?

Edit: Based on your update, you aren't telling Hibernate to configure itself from the config file. You're building your own Configuration and using that. You need to pick one or the other. Either do it programmatically, or do it via XML.

I was also facing the same problem Earlier my code was :

private final static SessionFactory factory = new Configuration()
        .configure().buildSessionFactory();

now I changed it to

private final static SessionFactory factory = new Configuration()
        .configure("hibernate.cfg.xml").buildSessionFactory();

And the error is gone.I think by default it looks for hibernate.properties file only.

The property name is hibernate.dialect

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

I dont know if there is anything like MySQL5Dialect.

Please refer to the documentation for further details.

Miladesnovakaina

The problem is just in configuring of configuration.

The configure() method of configuration class can get the path of config file of hibernate (hibernate.cfg.xml).

Just tell it the path. I think the problem will solved.

In mi case I resolved this by putting jars libs related to hibernate in WEB-INF\lib.

I also faced same error- org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect

I forgot to write cfg=cfg.configure(); while creating instance for persistence class.Now its running fine.

Configuration cfg=new Configuration();
              cfg=cfg.configure();
        sfactory=cfg.buildSessionFactory();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!