刚刚接触Hibernate尝试写一个事例项目,但是搞了一天硬是苦逼的没弄通,一直的报无法创建表,现在就把这些经验给大家分享一下:
1、书写问题:
<property name="hbm2ddl.auto">create</property>
中间可以是create或update,当无法创建表时,大家一定要注意检查一下自己写的是否正确
2.Mapping的映射文件有重名的,如:
<mapping resource="com/runsky/domain/Status.hbm.xml" /> <mapping resource="com/runsky/domain/Status.hbm.xml" />
3.表中有关键字,如:
order,level,address,degree,from等。(本人就是使用了from关键字)
4.在配置文件中不小心写了两个同名属性,如:
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="org.hibernate.auction"> <class name="com.runsky.domain.AdditionalInformation" table="AdditionalInformation" lazy="false"> <id name="id" column ="ID" length="32"> <generator class="uuid.hex"/> </id> <property name="tag" column ="tag" /> <property name="content" column ="content" /> <property name="id" column ="id" /> </class> </hibernate-mapping>
5.全类名写错了