now i have a hbm.xml file of a self nested table ad following:
Code:
<?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="test.Operation" table="T_Operation"
dynamic-update="false" dynamic-insert="false">
<id name="id" column="OperID" type="string" length="5">
<generator class="assigned"/>
</id>
<property name="parentId" type="string" update="true"
insert="true" column="ParentID" length="5"/>
<property name="operName" type="string" update="true"
insert="true" column="OperName" length="20"/>
<property name="description" type="string" update="true"
insert="true" column="Description" length="128"/>
<many-to-one name="parent" class="test.Operation" cascade="none"
outer-join="auto" update="true" insert="true" column="ParentID"
not-null="false"/>
<set name="operations" table="T_Operations" lazy="false"
inverse="true" cascade="all" sort="unsorted">
<key column="ParentID"/>
<one-to-many class="test.Operation" />
</set>
</class>
</hibernate-mapping>
Code:
package com.regical.eoss.db;
import java.util.Set;
/**
* @hibernate.class table="T_Operation"
*/
public class Operation {
private String id;
private String parentId;
private String operName;
private String description;
private Set operations;
private Operation parent;
/**
* @hibernate.id generator-class="assigned" column="OperID"
* type="string" length="5"
* @return
*/
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
/**
* @hibernate.property column="ParentID" type="string" length="5"
* @return
*/
public String getParentId() {
return parentId;
}
public void setParentId(String id) {
this.parentId = id;
}
/**
* @hibernate.property column="OperName" type="string" length="20"
* @return
*/
public String getOperName() {
return operName;
}
public void setOperName(String name) {
this.operName = name;
}
/**
* @hibernate.property column="Description" type="string" length="128"
* @return
*/
public String getDescription() {
return this.description;
}
public void setDescription(String desp) {
this.description = desp;
}
/**
* @hibernate.many-to-one role="parent" column="ParentID" not-null="false"
* class="com.regical.eoss.db.Operation"
*/
public Operation getParent() {
return parent;
}
public void setParent(Operation oper) {
parent = oper;
}
/**
* @hibernate.set role="ChildOpers" table="T_Operations" cascade="all"
* inverse="true"
* @hibernate.collection-key column="ParentID"
* @hibernate.collection-one-to-many class="com.regical.eoss.db.Operation"
* @param opers
* @return
*/
public Set getOperations() {
return operations;
}
public void setOperations(Set opers) {
this.operations = opers;
}
}
When i use this class to insert data to the table, hibernate throws following exception :
Code:
net.sf.hibernate.MappingException: Repeated column in mapping for class com.regical.eoss.db.Operation should be mapped with insert="false" update="false": ParentID
If I define insert="false" & update="false" for parentid attribute, the program run normally. but i check the table, I find there is no parentid data for every row.
How can i do?