今天在ubuntu下学习hibernate的使用,,刚开始出现了Table 'hibernate.news_table' doesn't exist这种问题,后来google一下,明白了是自己的数据库方言问题,我自己用的是mysql5.5然后改成了现在的样子
<!-- 制订数据库方言 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
原来是
<!-- 指定数据库方言 -->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
mysql5.0以后都是用上面那个,
然后我又把mysqljdbc的驱动文件改成了5.0,我资源里面有
最后附上正确的代码
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!-- hibernate-configuration是链接配置文件的根元素 -->
<hibernate-configuration>
<session-factory>
<!-- 指定数据库链接所用的驱动 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- 指定链接的url,数据库名 -->
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<!-- 用户名 -->
<property name="connection.username">root</property>
<!-- 密码 -->
<property name="connection.password">19921218</property>
<!-- 指定最大连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 指定连接池最小连接数 -->
<property name="hibernate.c3p0.min_size">1</property>
<!-- 指定连接池里链接的超时时常 -->
<property name="hibernate.c3p0.timeout">5000</property>
<!-- 指定连接池最大缓存多少个statement -->
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
<!-- 制订数据库方言 -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!-- 很据需要自动创建数据表 -->
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<!-- 罗列所有映射文件 -->
<mapping resource="j2ee/zhangjun/test/News.hbm.xml"/>
</session-factory>
</hibernate-configuration>