0 Replies Latest reply on Dec 11, 2008 10:03 AM by jfrankman

    Map OneToMany to a TablePerHierarchy subclass

    jfrankman Novice

      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.