I have the following hibernate.cfg.xml
:
<hibernate-configuration>
<session-factory>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/EJB</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</property>
<!-- Snip -->
Which I consume using this line:
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Then, elsewhere I try this:
SimpleSelect pkSelect = new SimpleSelect(Dialect.getDialect());
Which results in the following exception:
org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
Note, the following extract from the logs:
02:26:48,714 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
02:26:48,717 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
02:26:48,909 DEBUG Configuration:1387 - hibernate.dialect=org.hibernate.dialect.MySQLDialect
Any ideas what I'm doing wrong?
The javadoc of getDialect()
says:
Get an instance of the dialect specified by the current System properties.
So you have to have hibernate.dialect
configured in hibernate.properties
for this method to work.
Use SessionFactoryImplementor#getDialect()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With