Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #3056

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

From Arved Sandstrom <asandstrom3minus1@eastlink.ca>
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8
MIME-Version 1.0
Newsgroups comp.lang.java.programmer
Subject Re: EJB entity with multiple parents (only one relationship persists?)
References <0fb6a143-c58b-45b5-b6a8-26dac6883107@17g2000prr.googlegroups.com>
In-Reply-To <0fb6a143-c58b-45b5-b6a8-26dac6883107@17g2000prr.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Lines 42
Message-ID <qGrpp.9786$8U5.9241@newsfe20.iad> (permalink)
X-Complaints-To abuse@newsgroups-download.com
NNTP-Posting-Date Thu, 14 Apr 2011 01:00:06 UTC
Organization Public Usenet Newsgroup Access
Date Wed, 13 Apr 2011 22:00:05 -0300
Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!feed.ac-versailles.fr!proxad.net!feeder1-2.proxad.net!74.125.46.80.MISMATCH!postnews.google.com!news2.google.com!border1.nntp.dca.giganews.com!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe20.iad.POSTED!8ad76e89!not-for-mail
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3056

Show key headers only | View raw


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 shit

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

EJB entity with multiple parents (only one relationship persists?) ses <stewart@ssims.co.uk> - 2011-04-13 14:51 -0700
  Re: EJB entity with multiple parents (only one relationship persists?) Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-04-13 22:00 -0300

csiph-web