日期:2014-05-17  浏览次数:20800 次

hibernate主表保存从表保存不了
主表配置
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class name="notes.po.NotesPO"
table="OA_NOTES" schema="OFFICE">

<id name="notesID" type="java.lang.String" column="NOTESID">
<generator class="assigned" />
</id>

<property name="notesTitle" type="java.lang.String" column="NOTESTITLE"
length="200" />

<set name="notesMsg" table="OA_NOTESMSG" 
lazy="true" inverse="false" cascade="all">
<key column="NOTESID" />
<one-to-many class="notes.po.NotesMsgPO" />
</set>

</class>
</hibernate-mapping>

从表配置
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/ http://hibernate.sourceforge.net/
-->

<class name="notes.po.NotesMsgPO"
table="OA_NOTESMSG" schema="OFFICE">

<id name="msgID" type="java.lang.String" column="MSGID">
<generator class="assigned" />
</id>

<property name="userName" type="java.lang.String" column="USERNAME"
length="100" />

<many-to-one name="notes"
class="notes.po.NotesPO" column="NOTESID"
insert="true" update="true" />

</class>
</hibernate-mapping>

主表实体
public class NotesPO implements Serializable {
private String notesID;
private String notesTitle;

private Set notesMsg = new HashSet();

public NotesPO() {

}

public String getNotesID() {
return this.notesID;
}

public String getNotesTitle() {
return this.notesTitle;
}


public Set getNotesMsg() {
return this.notesMsg;
}



public void setNotesID(String notesID) {
this.notesID = notesID;
}

public void setNotesTitle(String notesTitle) {
this.notesTitle = notesTitle;
}

public void setNotesMsg(Set notesMsg) {
this.notesMsg = notesMsg;
}



public boolean equals(Object other) {
if (!(other instanceof NotesPO)) {
return false;
}
NotesPO castOther = (NotesPO) other;
return new EqualsBuilder().append(getNotesID(), castOther.getNotesID())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder().append(getNotesID()).toHashCode();
}

public String toString() {
return new ToStringBuilder(this).append("notesID", getNotesID())
.toString();
}

}

从表实体

public class NotesMsgPO implements Serializable {
private String msgID;
private String userName;
private NotesPO notes;

public NotesMsgPO() {

}


public String getMsgID() {
return this.msgID;
}