Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » OneToMany associations
OneToMany associations [message #385412] Thu, 29 January 2009 19:59 Go to previous message
David J Rericha is currently offline 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
 
Read Message
Read Message
Previous Topic:UpdateAllQuery does not seem to execute
Next Topic:Replacing collections
Goto Forum:
  


Current Time: Sat May 25 16:17:37 EDT 2013

Powered by FUDForum. Page generated in 0.01553 seconds