[hibernate-users] (no subject)
Walden Mathews
wmathews at aladdincapital.com
Tue Sep 4 10:57:53 EDT 2007
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() {...}
}
@Entity public abstract class Trade {
...
@ManyToOne public Security getSecurity() {...}
}
@Entity public class Allocation extends Trade {...}
When I try to update (merge) an Allocation, the query and error I get
from Hibernate look like this:
Query:
[org.hibernate.SQL] select allocation0_.id as id9_10_, etc., ... where
allocation0_.security_id=? and allocation0_.DTYPE='alloc'
Error:
[org.hibernate.type.LongType] could not bind value '1st Lien Term Loan'
to parameter: 1; com.xyz.entity.Security
In the error message, '1st Lien Term Loan' is the toString() value of
the associated Security, not it's long getId() value, as I would have
expected.
I have also tried giving the one-to-one a different name on the owner
side:
@Entity public class Security {
...
@OneToMany(mappedBy="security") public Collection<Trade>
getTrades() {...}
@OneToOne(mappedBy="issue") public Allocation
getAllocation() {...}
}
@Entity public abstract class Trade {
...
@ManyToOne public Security getSecurity() {...}
}
@Entity public class Allocation extends Trade {
...
@OneToOne public Security getIssue() {
return super.getSecurity();
}
}
But the result is the same.
Does anyone know what the problem is here, or am I using the wrong
approach? Any pointers would be much appreciated.
Thanks,
wmathews at aladdincapital.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-users/attachments/20070904/0f283562/attachment.html
More information about the hibernate-users
mailing list