Java Hibernate:没有设置方言。设置hibernate.dialogue属性
我有以下Java Hibernate:没有设置方言。设置hibernate.dialogue属性,java,hibernate,Java,Hibernate,我有以下hibernate.cfg.xml: <hibernate-configuration> <session-factory> <property name="hibernate.format_sql">true</property> <property name="hibernate.show_sql">true</property> <property name="h
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 -->
然后,我在其他地方尝试了以下方法:
SimpleSelect pkSelect = new SimpleSelect(Dialect.getDialect());
这将导致以下异常:
org.hibernate.HibernateException: The dialect was not set. Set the property hibernate.dialect.
请注意,以下是日志摘录:
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
你知道我做错了什么吗?GetDialante()的javadoc说: 获取当前系统属性指定的方言的实例 因此,必须在
hibernate.properties
中配置hibernate.dialogue
,此方法才能工作
使用
SessionFactoryImplementor#getdialante()
谢谢,但这并不是真正的问题。正在读取配置文件,并初始化方言,如日志中所示。(我已经用表明文件已被读取的日志更新了问题)
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