-
1. Re: How to save entities with PrimaryKeyJoinColumn?
itsme Jan 17, 2008 2:24 AM (in response to drathnow)Hi,
how are the id fields of both classes defined?
Normally sequences generate keys as per call. So both entities are serialized to different tables and for this, they get different id values. Only the referencing field must have the same value. -
2. Re: How to save entities with PrimaryKeyJoinColumn?
drathnow Jan 17, 2008 9:37 AM (in response to drathnow)But the referencing key is the primary key of the entity. Isn't that what @PrimaryKeyJoinColumn is suppose to imply? I would've assumed there would be some way for the implementation to realize this and setup the keys appropriately.
I've tried a couple of different strategies all with the same results. But here is what I've got now:
public class Field {
@Id
@SequenceGenerator(name = "fieldname_seq", sequenceName = "fieldname_seq")
@GeneratedValue(strategy = SEQUENCE, generator = "fieldname_seq")
private long fieldId;
}
public class FieldAccess {
@Id
private long fieldId;
} -
3. Re: How to save entities with PrimaryKeyJoinColumn?
itsme Jan 17, 2008 9:57 AM (in response to drathnow)ejb3-persistence spec only says, that @PrimaryKeyJoinColumn gives you the ability to name the corresponding column name different then the referenced column name in the child entity table.
So both entities find each other by the referenced column. This column is created as an additional column at the childs table referencing the primary key of the parents table. -
4. Re: How to save entities with PrimaryKeyJoinColumn?
drathnow Jan 17, 2008 11:51 AM (in response to drathnow)I have to admit that I've not read the spec but I've read a couple of books that say the PrimaryKeyJoinColumn joins entities over their primary keys, no other columns are involve.
If what you're saying is true, how is this different than a OneToOne relationship? What you're describing sounds to me like a OneToOne relationship. -
5. Re: How to save entities with PrimaryKeyJoinColumn?
jeff.rosen Apr 8, 2008 4:33 PM (in response to drathnow)I'm taking a wild guess here, but you're defining 2 entities that have a one-to-one relationship and are joined by their primary keys, so have you implemented those semantics in your java classes? For example, what happens if I call setFieldId on Field, does it's associated FieldAccess instance have it's fieldId kept in sync? What about vice versa? And for the getters?
Given the life-cycles of each type, can you get by with a single fieldId property in just one of the classes?