我正在使用hibernate orm,我有2个表与一对多的关系,我无法找出为什么hibernate不会创建我的一个表(杂志表)。 我正在使用hbm2dll自动创建表。
Magazine.hbm.xml
<hibernate-mapping>
<class name="ir.sheentech.school.model.magazine.Magazine" table="magazine">
<id name="magID" type="java.lang.Integer">
<column name="MAG_ID"></column>
<generator class="identity"></generator>
</id>
<property name="magName" column="MAG_NAME" type="java.lang.String" not-null="true"></property>
<property name="desc" column="DESC" type="java.lang.String" ></property>
<set name="entesharat" table="entesharat" inverse="true" cascade="all">
<key>
<column name="MAG_ID" not-null="true"></column>
</key>
<one-to-many class="ir.sheentech.school.model.magazine.Entesharat"/>
</set>
</class>
Entesharat.hbm.xml
<hibernate-mapping>
<class name="ir.sheentech.school.model.magazine.Entesharat" table="entesharat">
<id name="id" type="java.lang.Integer">
<column name="ID"></column>
<generator class="identity"></generator>
</id>
<property name="name" column="NAME" type="java.lang.String" not-null="true"></property>
<many-to-one name="magazine" column="MAG_ID" class="ir.sheentech.school.model.magazine.Magazine" not-null="true" > </many-to-one>
</class>
的hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/school?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.connection.CharSet">utf8</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
<property name="hbm2ddl.auto">update</property>
</session-factory>
Magazine.java
public class Magazine {
private Integer magID;
private String magName;
private Set<Entesharat> entesharat = new HashSet<Entesharat>(0);
private String desc;
public Integer getMagID() {
return magID;
}
public void setMagID(Integer magID) {
this.magID = magID;
}
public String getMagName() {
return magName;
}
public void setMagName(String magName) {
this.magName = magName;
}
public Set<Entesharat> getEntesharat() {
return entesharat;
}
public void setEntesharat(Set<Entesharat> entesharat) {
this.entesharat = entesharat;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
Entesharat.java
public class Entesharat {
private Integer id;
private String name;
private Magazine magazine;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Magazine getMagazine() {
return magazine;
}
public void setMagazine(Magazine magazine) {
this.magazine = magazine;
}
}
答案 0 :(得分:0)
问题出现在下面的代码中
magazine.hbm.xml
<property name="desc" column="DESC" type="java.lang.String" ></property>
DESC是mysql中的关键字