hibernate自动更新时方言问题

 hibernate.cfg.xml

 HTML Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
<?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.MySQLDialect -->
        org.hibernate.dialect.MySQL5Dialect
    </property>
    <property name="connection.url">
        jdbc:mysql://localhost:3306/test
    </property>
    <property name="connection.username">root</property>
    <property name="connection.password">root</property>
    <property name="connection.driver_class">
        com.mysql.jdbc.Driver
    </property>
    <property name="myeclipse.connection.profile">mysql</property>
    <property name="show_sql">ture</property>
    <property name="hbm2ddl.auto">update</property>
    <mapping resource="com/leejuen/hibernate/Student.hbm.xml" />

</session-factory>

</hibernate-configuration>

在学习这里时按照书上打的使用了 
<property name="hbm2ddl.auto">update</property>这个配置。这样会自动在mysql中建表。但实验时没有出现表。而是会出现没有test.student表的报错。但若是mysql中有这张表却会正常更新sql。其原因是应为mysql的方言设置问题。我的mysql用的是5以上的版本方言要设置成 org.hibernate.dialect.MySQL5Dialect 。这样就能正常使用。谢谢网友小笼包zzz。

PS:还有博客中的代码高亮可以使用codeformat这个软件。是ACM的上古大牛做的很好用 

 

posted @ 2014-02-26 13:04  leejuen  阅读(150)  评论(0编辑  收藏  举报