-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: composite-id for new entities
PostPosted: Mon Aug 15, 2011 9:20 am 
Newbie

Joined: Wed Jun 22, 2011 11:37 am
Posts: 4
<class name="Employee" table="tbl_employee">
<id name="id">
<generator class="native" />
</id>
<set name="departments" lazy="true" inverse="true" cascade="all">
<key column="employee_id" />
<one-to-many class="EmployeeDepartment" />
</set>
</class>

<class name="EmployeeDepartment" table="tbl_employee_dep">
<composite-id name="id" >
<key-property name="departmentId" column="department_id" />
<key-property name="employeeId" column="employee_id" />
</composite-id>
.....
</class>

<class name="Department" table="tbl_department">
<id name="id">
<generator class="native" />
</id>
.....
</class>

public class EmployeeDepartment {
private EmployeeDepartmentID id;
private Employee employee;
private Department department;
....

}

public class EmployeeDepartmentID {
private int employeeId;
private int departmentId;
}


The problem is: when I create a new Employee a Department is assigned to that employee BEFORE that employee is saved. Because of that the EmployeeDepartmentID.employeeId cannot be set (becase Employee.id is null). Is there a way Hibernate will automatically set EmployeeDepartmentID.employeeId for me or there's some even I can intercept and populate that myself in code?

Thank you.


Top
 Profile  
 
 Post subject: Re: composite-id for new entities
PostPosted: Mon Aug 15, 2011 12:11 pm 
Newbie

Joined: Wed Jun 22, 2011 11:37 am
Posts: 4
To reply to my own question, this can be easily done using a generator. Can be closed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.