-
1. Re: Hibernate not copying primary key into associated object
epbernard Feb 9, 2006 4:51 PM (in response to tpedone)une @GenericGenerator and foreign
-
2. Re: Hibernate not copying primary key into associated object
tpedone Feb 9, 2006 7:01 PM (in response to tpedone)Thanks.
That worked I had to create an inverse One to One relationship from the CoreMessagePayload to the CoreMessage. Then tell the CoreMessagePayload to use the id of the referenced CoreMessage object. -
3. Re: Hibernate not copying primary key into associated object
dbudworth Feb 24, 2006 8:08 PM (in response to tpedone)tpedone, could you possibly post the relevant tags you put on your classes to get this to work?
Spent the last 5 hours spinning my wheels on getting true OneToOnes working (where child pk = fk to parent pk).
After trying combinations of @GenericGenerator(foreign) placed all around ( I can't find an example that says where the actual annotation belongs, so I tried the pk of the child with no luck).
I eventually gave up and decided to redo all my tables to use sequence pk for child and plain old unique fk to parent. Which seems to still not work. (entity manager attempts to insert null in fk column even though i set parent.setChild(ch) and child.setParent(pa) in the code that creates the entities.
Thanks -
4. Re: Hibernate not copying primary key into associated object
tpedone Feb 24, 2006 8:21 PM (in response to tpedone)Here's the id of the CoreMessagePayload:
@Id(generate=GeneratorType.SEQUENCE, generator="SEQ_STORE")
@Column(name="MESSAGEID", nullable=false)
public Long getId()
{
return mId;
}
Notice that it is using the MessageID sequence we had originally defined for the Message. Then the Message class defines it's id as:
@Id (generator="fk")
@GenericGenerator(name="fk", strategy = "foreign",
parameters = {
@Parameter(name="property", value = "payload")
}
)
@Column(name="messageID", nullable=false)
public Long getId()
{
return mId;
}
Finally, the message has a reference to a MessagePayload:
@OneToOne(cascade=CascadeType.ALL)
@PrimaryKeyJoinColumn
public CoreMessagePayload getPayload()
{
return mPayload;
}
Couple of things to note:
1) We're still using EJB 3.0 RC3, I belive the Generator tags have changed since then.
2) We changed our object model so that Message and MessagePayload are true one to one. Before, you could have a message without a payload. Now you can't. That let us define generate the id in the Payload instead of the Message since you can only use the foreign strategy from the entity that does not generate the pk.
Tim