Need help with m-n mapping....
mdelamere Apr 15, 2003 7:44 AMHi,
I?m starting to go nuts with my n-m mapping :-). I?ve read various docs and
have gone through the archive but I haven?t been able to get any wiser on
this. Below you can see the code for adding ProfileValues to my relation
profiles-collection in the CustomerValue. I then pass the CustomerValue to my
sessionfacade which is supposed to handle the storing of my relationship
customer<->profile. For some reason though the customer values are set
correctly in the relationship table but the profile values have been newly
created producing new values as apposed to writing the values that I passed
to the session facade! If I then comment out the sequence key generation in
my profile create method and just set the id form my profileValue object I
get a "Entity with primary key [.139.] already exists" exception!?
Could someone PLEASE help me on getting my relationship table filled with
the correct values......
I would be very grateful for any help given.
Thanks,
Michael
wrong:
--------------------------
customer_id | profile_id
--------------------------
22 | 190 | new value instead of value
22 | 191 | passed to sessionfacade
22 | 192 | which is 139
---------------------------
--------------------------------------------------------
Client code: (processing form data)
--------------------------------------------------------
/**
* Client code for creating new ProfileValues from form input
* and adding to customer (relation) collection
*/
public static CustomerValue addProfiesToCustomer(String[] profiles,
CustomerValue cv) {
for (int i = 0; i < profiles.length; i++) {
ProfileValue pv = new ProfileValue(new Integer(profiles), null,
null);
cv.addprofile(pv);
}
return cv;
}
--------------------------------------------------------
Profiles Sessionfacade code (storing to relation table)
--------------------------------------------------------
/**
* Store the Customer-Profile relation in the relation table
* using the values passed from the client code above
*/
public void storeCustomerProfiles(CustomerValue cv) {
CustomerLocalHome home = null;
try {
home = (CustomerLocalHome) CustomerUtil.getLocalHome();
CustomerLocal cl = home.findByPrimaryKey(new
CustomerPK(cv.getId()));
cl.setCustomerValue(cv);
} catch(Exception e) {
}