我的hibernate.cfg.xml起先配置是:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ORCLLIB</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.password">tiger</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="show_sql">true</property>
<mapping resource="com/ray/entity/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
然后就弹出异常Exception:Unable to access java.sql.DatabaseMetaData to determine appropriate Dialect
解决方法就是在配置文件session-factory里加一条:<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
最后正确的是:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:ORCLLIB</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.password">tiger</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="show_sql">true</property>
<mapping resource="com/ray/entity/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>