This is more of a straight JPA question, but I want to make sure Glassfish is doing the right thing.
For this example, I have a PostalAddress class (city, state, postal code, etc.) and a PostalAddressLine class. The PostalAddress class has a @OneToMany relationship with the PostalAddressLine class, as you might expect:
[code]
@OneToMany(mappedBy="postalAddressEntity", cascade=CascadeType.ALL, fetch=FetchType.EAGER)
protected List<PostalAddressLine> getPostalAddressLines() {
return this.postalAddressLines;
}
protected void setPostalAddressLines(final List<PostalAddressLine> lines) {
this.postalAddressLines = lines;
}
[/code]
...and the PostalAddressLine class, in turn, has a @ManyToOne relationship with its owning/containing PostalAddress:
[code]
@ManyToOne(optional=false)
@JoinColumn(name="PostalAddressID", nullable=false)
protected PostalAddressEntity getPostalAddressEntity() {
return this.postalAddressEntity;
}
protected void setPostalAddressEntity(final PostalAddressEntity postalAddressEntity) {
this.postalAddressEntity = postalAddressEntity;
}
[/code]
If I create a new PostalAddress instance, and set its postalAddressLines property with a List of PostalAddressLines (so none of these objects has IDs yet), and then merge() the as-yet-unpersisted PostalAddress instance, what is supposed to happen? I [i]believe[/i] I am seeing some cases where new PostalAddressLines are not being created. Before I report this or write it up, I'd like to make sure I'm not doing something boneheaded. Perhaps I have a Cascade operation or something that is missing?
I [i]am[/i] taking care to ensure that the PostalAddressLines are being created with a reference to the PostalAddress of which they are a part, but it dawns on me that I'm not really even sure what is [i]supposed[/i] to happen in a one-to-many scenario when neither the "one" nor the "many" has ever been persisted.
Thanks,
Laird
[Message sent by forum member 'ljnelson' (ljnelson)]
http://forums.java.net/jive/thread.jspa?messageID=225554