2007/9/4, Walden Mathews <wmathews(a)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