簡體   English   中英

Hibernate:沒有設置方言。 設置屬性hibernate.dialect

[英]Hibernate: The dialect was not set. Set the property hibernate.dialect

我有以下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 -->

我用這條線消耗的:

sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();

然后,在其他地方我試試這個:

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

我有什么想法我做錯了嗎?

getDialect()的javadoc說:

獲取當前系統屬性指定的方言實例。

因此,您必須在hibernate.dialect配置hibernate.properties才能使此方法正常工作。

使用SessionFactoryImplementor#getDialect()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM