2010-06-29 23 views
3

我有以下hibernate.cfg.xml属性:这一点我消耗使用这条线休眠:方言没有设置。设置hibernate.dialect

<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 

任何想法我做错了吗?

回答

4

getDialect()的Javadoc说:

获取当前系统属性中指定的方言的一个实例。

因此,您必须在hibernate.properties中配置hibernate.dialect以使此方法正常工作。使用SessionFactoryImplementor#getDialect()

+0

谢谢,但这不是真正的问题。正在读取配置文件,并且Dialect被初始化,如日志中所示。 (我已经更新了问题与日志,表明该文件被读取) – 2010-06-29 06:28:49

+0

@Matty皮特看到我的更新 – Bozho 2010-06-29 08:29:29

+0

啊。得到它了。谢谢 – 2010-06-29 12:02:45