[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Map OneToMany to a TablePerHierarchy subclass
jfrankman
do-not-reply at jboss.com
Thu Dec 11 10:03:40 EST 2008
Is there a way to establish a OnetoMany relationship with only the subclass of TablePerHierarchy mapped entity?
I have an entity class A mapped as a table per hierarchy strategy. There is a class B that is assiciated with only one of the subclasses of class A. When I establish the OnetoMany from class B to one of class A's subclasses I get a classcastexception because the generated query does not filter on the subclass but still returns all records regardless of type. Here are the class mappings:
| @Entity
| @Table(name = "FBPROPERTY")
| public class PropertyVO
| {
| ...
| @OneToMany
| @JoinColumns( { @JoinColumn(name = "itemid", referencedColumnName = "propertyid") })
| public Set<PropertyLineItemLienVO> getLineItemLiens()
| {
| return lineItemLiens;
| }
| }
|
| @Entity
| @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
| @DiscriminatorColumn(name = "TYPEID", discriminatorType = DiscriminatorType.INTEGER)
| @Table(name = "FBLINEITEMLIENS")
| @Name("lineItemLienVO")
| public class LineItemLienVO implements Serializable
| {
| ...
| }
|
| @Entity
| @DiscriminatorValue("1")
| @Name("propertyLineItemLien")
| public class PropertyLineItemLienVO extends LineItemLienVO implements Serializable
| {
| .....
| }
|
I realize this is not based on the cleanest DB design, but I do not have the option to re design the database. I need to associate PropertyVO with the PropertyLineItemLienVO subclass of LineItemLienVO. As a side note, I also tried to modify the relationship by using the @Filter annotation, but it looks like JBoss ignores this annotation.
Thanks.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4195956#4195956
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4195956
More information about the jboss-user
mailing list