如何配置Hibernate支持MySql

03-09-05 wangkent

配置Tomcat+MySql+Hibernate

我修改了Hibernate.properties设置使用PostgreSQLDialect

hibernate.dialect net.sf.hibernate.dialect.MySQLDialect

hibernate.connection.driver_class org.gjt.mm.mysql.Driver

hibernate.connection.driver_class com.mysql.jdbc.Driver

hibernate.connection.url jdbc:mysql:MyTest

hibernate.connection.username root

hibernate.connection.password root

修改hibernate.cfg.xml如下

<hibernate-configuration>

<session-factory>

<property name="connection.datasource">MyTest</property>

<property name="show_sql">false</property>

<property name="use_outer_join">true</property>

<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->

<mapping resource="Cat.hbm.xml"/>

</session-factory>

但是程序运行到InitialHibernate处出现以下错误

javax.naming.NameNotFoundException: Name gt3k is not bound in this Context

请指点

// 在此输入java代码
<p>

1
ax3536
2003-09-05 22:19

hibernate.connection.url jdbc:mysql:MyTest

你这是什么意思?URL不对!

tiyi
2003-09-05 23:43

其实可以直接使用jndi的,这样就避免了在hibernate上的配置.

tiyi
2003-09-05 23:45

为什么你又有progreSQL又有mysql ?

按照错误 是 gt3k 这个jndi-name找不到.

changdelphi
2008-12-05 21:23

我原来配置mysql的例子:你参考一下吧

<hibernate-configuration>

<session-factory>

<property name="show_sql">true</property>

<property name="connection.username">root</property>

<property name="connection.url">jdbc:mysql://localhost:3306/computer</property>

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="connection.password">123456</property>

<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>

<property name="hibernate.max_fetch_depth">10</property>

<property name="hibernate.cache.use_query_cache">true</property>

<property name="hibernate.jdbc.batch_size">0</property>

<mapping resource="abc.hbm.xml" />

</session-factory>

</hibernate-configuration>