0 Replies Latest reply on Nov 10, 2006 10:23 AM by divxyoda

    Advanced problems with Jboss and Hibernate !

    divxyoda

      Hi every body,
      Look at these classes examples to see my problems with hibernate on jboss (for a mySql database) and understand what i want to do :

      @Entity
      @Table(name=Mother)
      @Inheritance(strategy = InheritanceType.JOINED)
      public class Mother implements Serializable{
      @Id
      private String mother_id;
      public Mother(){}

      //... getters/setters generated for all fields members
      }

      Note : The Mother table has a single primary key : its id



      @Embeddable
      public Class DaughterKey implements Serializable{
      private String mother_Id;
      private String daughter_id;
      public DaughterKey(){}

      //getters/setters generated for the both fields

      // the methods : toString(),hasCode(),equals() are overrided
      }

      Note : the DaughterKey is a class that specifies (according to my understandings) a composite primary key class when mappings happen !



      @Entity
      @Table(name = "Daughter")
      @IdClass(DaughterKey.class)
      @PrimaryKeyJoinColumn(name = "Mother_id")
      public class Daughter extends Mother{
      @Id
      private String daughter_id;
      public Daughter(){ super();}

      //.. getter/setter for all fields
      }

      Note: the Daughter table has a composite key (mother_Id+daughter_id).




      So,the idea is that eventhough a Daughter Class extends a Mother Class, the Daughter must have 2 fields-members as PrimaryKey in the Database (the mother_id and its own daughter_id) : a composite key.

      After compiling and creating a JAR file, I try to deploy the JAR-file and i have a such exception :

      java.lang.reflect.InvocationTargetException
      //.... at ....
      caused by

      org.hibernate.AnnotationException : Unable to define/override @Id(s) on a subclass : Daughter.

      Thanks a lot if someOne can help me, I know that it's because my conception is not correct but I can't get any better ided.


      PS : Ask your questions, if you don't understand my idea !
      Best regards, Divx.