hi,guys
I have two class that have mang-to-one relationship.
I have an Object Department(1) Linked to another Object Employee(2),
Source Department:
<class name="test.Department" table="department">
<id name="id" type="string" unsaved-value="any">
<column name="id" sql-type="varchar(32)" not-null="true"/>
<generator class="assigned"/>
</id>
<property name="name" type="string" update="true" insert="true">
<column name="name" sql-type="varchar(150)" not-null="false"/>
</property>
<property name="fatherId" type="string" update="true" insert="true">
<column name="father_id" sql-type="varchar(32)" not-null="false"/>
</property>
<set name="employee" lazy="true" inverse="true" cascade="all">
<key column="id"/>
<one-to-many class="test.Employee"/>
</set>
Source Employee:
<class name="test.Employee" table="employee">
<id name="id" type="string" unsaved-value="any">
<column name="id" sql-type="varchar(32)" not-null="true"/>
<generator class="assigned"/>
</id>
<property name="name" type="string" update="true" insert="true">
<column name="name" sql-type="varchar(80)" not-null="false"/>
</property>
<property name="password" type="string" update="true" insert="true">
<column name="password" sql-type="varchar(30)" not-null="false"/>
</property>
<many-to-one name="department" class="test.Department" >
<column name="id" sql-type="varchar(32)" not-null="true"/>
</many-to-one>
</class>
....
Employee employee=new Employee();
employee.setId("0001");
employee.setName("test1");
employee.setPassword("111");
Department dp=new Department();
dp.setId("dp1");
dp.setName("software design");
Set employeeSet=new HashSet();
employeeSet.add(employee);
dp.setEmployee(employeeSet);
....
session.save(dp);
....
sucess!
but when i...
Department department=new Department();
department.setId("dp1");
Employee employee=new Employee();
employee.setId("0002");
employee.setName("test2");
employee.setPassword("111");
employee.setDepartment(department);
....
session.save(employee);
....
it reports:
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: test.Employee.department
please tell me how to do this
thanks
Feeler
[/b]
|