File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes EJB3 double reference issue. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "EJB3 double reference issue." Watch "EJB3 double reference issue." New topic

EJB3 double reference issue.

Adam Koprowski

Joined: Oct 22, 2007
Posts: 3
I'm having an issue with referencing an entity bean twice from other bean. Here's a simplified version of what I have:

Now, to begin with, is this allowed? If not, how can I achieve something like that? If so, then why am I getting errors while trying to delete objects of type Block? :-). I tried to play around with different cascading settings but nothing seems to help. I'm getting an error:

where the identifier is the key of the block which indeed occurs twice in the Items table, for two different items, but I do not see why should that be a problem.

Any help greatly appreciated!
Dianne Pop

Joined: May 07, 2003
Posts: 8
I have the exact same problem right now

Did you find a way to fix this?

I can't seem to use the mappings correctly for this case!
Stu Quinn
Ranch Hand

Joined: Feb 27, 2009
Posts: 35
If there is a need to keep track of Left & Right perhaps these can be subtypes.

Good luck,
Dianne Pop

Joined: May 07, 2003
Posts: 8
Unfortunately, splitting into LeftItem and RightItem would have no business meaning and it would be very confusing. I actually have several such fields, in several "parent" entities, and it could get really complicated really fast.

What I did do is remove the optional=false constraint, and it seems to work correctly now. The only problem is that I have to remember to always set the parent (Block), because the DB will not complain about it missing.

I agree. Here's the link:
subject: EJB3 double reference issue.
It's not a secret anymore!