hibernate自动更新时方言问题

本文详细介绍了Hibernate配置文件hibernate.cfg.xml的配置项及其作用,特别是针对MySQL5的方言设置问题进行了探讨。文中还解决了自动创建表失败的问题,并分享了一个代码高亮工具。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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的上古大牛做的很好用 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值