Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > EJB entity with multiple parents (only one relationship persists?)

Reply
Thread Tools

EJB entity with multiple parents (only one relationship persists?)

 
 
ses
Guest
Posts: n/a
 
      04-13-2011
I have an EJB entity relationship like the following

Customer ---one-many---> Booking
Location ---one-many---> Booking

Firstly I persist the booking. The problem is when I try to add the
same Booking entity to both Customer and Location, and then merge
customer and location the only relationship which remains in the
database is the one for which merge was called last.

This indicates that an individual Booking can only be 'owned' by one
entity, why is this the case and how can I circumvent it? Any
suggestions would be gratefully appreciated.

I'm using JPA with eager fetch type and orphan removal.
 
Reply With Quote
 
 
 
 
Arved Sandstrom
Guest
Posts: n/a
 
      04-14-2011
On 11-04-13 06:51 PM, ses wrote:
> I have an EJB entity relationship like the following
>
> Customer ---one-many---> Booking
> Location ---one-many---> Booking
>
> Firstly I persist the booking. The problem is when I try to add the
> same Booking entity to both Customer and Location, and then merge
> customer and location the only relationship which remains in the
> database is the one for which merge was called last.
>
> This indicates that an individual Booking can only be 'owned' by one
> entity, why is this the case and how can I circumvent it? Any
> suggestions would be gratefully appreciated.
>
> I'm using JPA with eager fetch type and orphan removal.


This is not the case: those relationships are possible. There's nothing
unusual about one entity having multiple @ManyToOne fields (in this case
Booking would have two).

Notionally, if you have a pre-existing Location, and a pre-existing
Customer, then doing what you describe inside a transaction (say, within
EntityTransaction boundaries, or within a session bean method that is a
JTA transaction) should work. I can only suggest supplying a pared-down
snippet of your code - extraneous setters are unnecessary, but include
all the EM operations, and everything to do with setting the
bidirectional relationships. I would tend to merge the Customer and
Location first thing, before setting the relationships to the new
Booking, and persisting the Booking, and perhaps you can try that.

Make sure you're using merge correctly, that if you use the Customer and
Location that it's the returned values that are used subsequently.

AHS

--
That's not the recollection that I recall...All this information is
certainly in the hands of the auditor and we certainly await his report
to indicate what he deems has occurred.
-- Halifax, Nova Scotia mayor Peter Kelly, who is currently deeply in
the ****
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible to generate "ejb-jar.xml" from EJB class (source)? "ejb-jar.xml" appserver independent? Raymond Schanks Java 0 08-03-2010 08:21 AM
How to relate a SQL based entity with an Object based entity in Entity Framework markla ASP .Net 1 10-06-2008 09:42 AM
How has your relationship with your Parents Strengthened or weakened? Sohaib Saleem Computer Support 6 05-24-2004 09:44 AM
EJB: How to delete child entries from a parent-child CMR one-to-many relationship? davout Java 0 04-18-2004 07:02 PM
EJB - Simple CMR one-to-one unidirectional relationship Patrick Maddox Java 0 08-01-2003 08:45 AM



Advertisments