| OneToMany associations [message #385412] |
Thu, 29 January 2009 19:59  |
David J Rericha Messages: 13 Registered: July 2009 |
Junior Member |
|
|
Dear members,
I am experimenting with OneToMany associations in the following senario:
Patient with addresses in a bi-directional one-to-many association (These
are rich patients). I also set cascade=ALL with @PrivateOwned.
I encountered the following:
1) In order to create a patient and add addresses, I must set the patient
in each address and then persist the patient. I cannot just add the
addresses to patient.addresses and save the patient (in this case the
patient and the addresses are saved, but the foreign key is not set in the
addresses). Is this the intended behavior?
2) I am not sure what @PrivateOwned accomplishes. I get the same behavior
with just cascade=ALL when persisting and removing the patient.
@Entity
@Table(name="test_patient")
public class Patient extends Model
{
...
@OneToMany(mappedBy = "patient", cascade = ALL )
@PrivateOwned
private List<Address> addresses = new ArrayList<Address>();...
}
@Entity
public class Address extends Model
{
...
@ManyToOne( fetch=LAZY)
@JoinColumn(name="pat_id", referencedColumnName = "ID")
private Patient patient;...
}
Regards,
David
|
|
|