[hibernate-users] (no subject)
Walden Mathews
wmathews at aladdincapital.com
Wed Sep 5 07:50:33 EDT 2007
Robert,
Thanks for the reply. You're right about my first example, but not the
second. The second creates a dedicated property and mapping for the
1:1.
I don't know of anything in the ejb spec or hibernate that prohibits
either of these schemes, but if there is such a prohibition I'd like to
know about it.
I agree with you, though, that there is nothing gained by trying to push
that 1:1 constraint down into the persistence layer, and so I have gone
with the strategy you proposed.
Thanks again,
Walden
-----Original Message-----
From: Robert Klemme [mailto:shortcutter at googlemail.com]
Sent: Wednesday, September 05, 2007 5:38 AM
To: Walden Mathews
Cc: hibernate-users at lists.jboss.org
Subject: Re: [hibernate-users] (no subject)
2007/9/4, Walden Mathews <wmathews at aladdincapital.com>:
>
>
>
>
> Hello,
>
>
>
> I'm using Jboss-4.0.5-GA in the ejb3 configuration. I'm trying to
implement
> the following entities and relationships, without success:
>
>
>
> Entity: Security
>
> Entity: Trade
>
> Entity: Allocation extends Trade
>
>
>
> Security->Trade is one-to-many with Trade as the relationship owner
>
> Trade->Security is many-to-one
>
> Security->Allocation is one-to-one with Allocation as the relationship
owner
>
> Allocation->Security is one-to-one
>
>
>
> The basic idea is that while a Security may have a collection of
Trades
> associated with it, at most one can be an Allocation. And if a
Security has
> an associated Allocation, then that Allocation must appear in the
Trades
> collection of the Security as well.
>
>
>
> I've tried this approach:
>
>
>
> @Entity public class Security {
>
> ...
>
> @OneToMany(mappedBy="security") public Collection<Trade>
> getTrades() {...}
>
> @OneToOne(mappedBy="security") public Allocation
> getAllocation() {...}
>
> }
I believe this is calling for trouble because you have *two*
relationships to the *same* class (in a way, because Allocation
inherits Trade) mapped by the *same* column. IMHO you should remove
the 1:1 to Allocation and ensure by your business logic that the Trade
collection contains only one allocation.
Maybe there is also bug in Hibernate which does not detect this
situation and issue a proper error message but IMHO the root cause is
your problem with the logic as stated above.
Kind regards
robert
More information about the hibernate-users
mailing list