[jboss-user] [EJB 3.0] - How to save entities with PrimaryKeyJoinColumn?
drathnow
do-not-reply at jboss.com
Wed Jan 16 20:03:04 EST 2008
Could someone give me some insight into the correct way to save entities that are joined over their primary key?
I have two entities: Field and FieldAccess. They both share the same primary key and have a relation over their primary key:
class Field {
@OneToOne (mappedBy = "field")
protected FieldAccess fieldAccess;
}
class FieldAccess {
@OneToOne
@PrimaryKeyJoinColumn(name = "fieldid", referencedColumnName = "fieldid")
protected Field field;
}
I'm using Oracle Sequences to generate primary keys.
When saving a new entity, how does the primary key get propagated from one entity to the other? I've tried the following but the primary keys never end up being the same:
FieldAccess fieldAccess = new FieldAccess();
entityManager.persist(fieldAccess);
Field field = new Field();
field.setFieldAccess(fieldAccess);
fieldAccess.setField(field);
entityManager.persist(field);
What am I missing?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4120689#4120689
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4120689
More information about the jboss-user
mailing list