1 Reply Latest reply on May 23, 2006 12:23 PM by Emmanuel Bernard

    @ManyToOne or @OneToOne using @JoinTable and @Inheritance ca

    Roderic Paulk Newbie

      I have experence a problem while mapping a legacy database when I am attempt to use @ManyToOne using @JoinTable and the parent class is declaired with @Inheritance(strategy=InheritanceType.JOINED). Here is a simplified version of what I am attempting:

      @Entity
      @Inheritance(strategy=InheritanceType.JOINED)
      @Table(name = "baseclass")
      public abstract class Baseclass implements java.io.Serializable {
      
       private String internalid;
      
       @Id
       @Column(name = "INTERNALID", unique = true, nullable = false, insertable = true, updatable = true, length = 34)
       public String getInternalid() {
       return this.internalid;
       }
       public void setInternalid(String internalid) {
       this.internalid = internalid;
       }
      }

      @Entity
      @Table(name = "parent")
      public class Parent extends Baseclass
      {
      
       private String name;
      
       public String getName(){
       return this.name;
       }
       public void setName(String name){
       this.name = name;
       }
      }

      @Entity
      @Table(name = "child")
      public class Child implements java.io.Serializable {
      
       private String internalid;
       private String name;
       private Parent parent;
      
       @Id
       @Column(name = "INTERNALID", unique = true, nullable = false, insertable = true, updatable = true, length = 34)
       public String getInternalid() {
       return this.internalid;
       }
       public void setInternalid(String internalid) {
       this.internalid = internalid;
       }
      
       public String getName(){
       return this.name;
       }
       public void setName(String name){
       this.name = name;
       }
      
       @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
       @JoinTable(name="hierarchy",
       joinColumns = @JoinColumn( name="childinternalid"),
       inverseJoinColumns = @JoinColumn( name="parentinternalid"))
       public Parent getParent(){
       return this.parent;
       }
       public void setParent(Parent parent){
       this.parent = parent;
       }
      }


      When I try this in JBOSSAS4.0.4GA I receive the following error:

      14:24:09,268 ERROR [AssertionFailure] an assertion failure occured (this may indicate a bug in Hiber
      nate, but is more likely due to unsafe use of the session)
      org.hibernate.AssertionFailure: Table hierarchy not found
       at org.hibernate.persister.entity.JoinedSubclassEntityPersister.getTableId(JoinedSubclassEntityPers
      ister.java:444)
       at org.hibernate.persister.entity.JoinedSubclassEntityPersister.<init>(JoinedSubclassEntityPersister.java:225)
       at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:58)
       at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:223)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1213)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:631)
       at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:760)
       at org.hibernate.ejb.Ejb3Configuration.createContainerEntityManagerFactory(Ejb3Configuration.java:3
      50)
       at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.
      java:119)
       at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
      
      ...
      



      If I switch the association to @OneToMany on the parent side there is no error.

      I have also experenced this same error using bidirectional @OneToOne with an association table where either end is using @Inheritance(strategy=InheritanceType.JOINED), and if I make it unidirectional on the end without @Inheritance(strategy=InheritanceType.JOINED) it does not throw the error.

      I'm not sure what I am doing incorrectly.