3 Replies Latest reply on Sep 1, 2005 6:40 AM by Emmanuel Bernard

    Mixing annotations and hbm.xml

    J-C jc Apprentice

      Is it possible to mix for the same entity bean annotations and hbm.xml ?

      In my application I have an interface Animal and several subclasses (Dog, Cat, ...). Since it seems that annotations to declare interface and subclasses are not supported (specified ??) in EJB3 (http://forum.hibernate.org/viewtopic.php?p=2238824#2238824), I'd like to declare in hbm.xml only the annotaions for the interface and to declare other fields of subclasses using ejb3 annotation:

      public interface Pet {
      int getId();
      void setId(int id);
      }
      
      @Entity()
      public class Dog {
      ...
      @ManyToOne
      public void getChildren() {
      ...}
      
      <hibernate-mapping>
      <class name="Pet"
       table="Pet" lazy="false">
       <id name="id" column="PET_ID">
       <generator class="native" />
       </id>
       <joined-subclass
       name="fr.biomerieux.dnachip.bo.classification.DefaultLeafBO"
       extends="fr.biomerieux.dnachip.bo.classification.Leaf"
       lazy="false">
       <key column="LEAF_ID" />
       <property name="name" />
       </joined-subclass>
       <joined-subclass name="fr.biomerieux.dnachip.bo.sample.SampleBO"
       extends="fr.biomerieux.dnachip.bo.classification.Leaf"
       lazy="false">
       <key column="LEAF_ID" />
       <property name="name" />
       <property name="elements" />
       <property name="site" />
       <many-to-one name="taxon" />
       </joined-subclass>
       </class>
      </hibernate-mapping>
      


        • 1. Re: Mixing annotations and hbm.xml
          J-C jc Apprentice

          Sorry, I rewriite the post, I made a mistake !!!


          "jc7442" wrote:
          Is it possible to mix for the same entity bean annotations and hbm.xml ?

          In my application I have an interface Animal and several subclasses (Dog, Cat, ...). Since it seems that annotations to declare interface and subclasses are not supported (specified ??) in EJB3 (http://forum.hibernate.org/viewtopic.php?p=2238824#2238824), I'd like to declare in hbm.xml only the annotaions for the interface and to declare other fields of subclasses using ejb3 annotation:
          public interface Pet {
          int getId();
          void setId(int id);
          }
          
          @Entity()
          public class Dog {
          ...
          @ManyToOne
          public void getChildren() {
          ...}
          
          <hibernate-mapping>
          <class name="Pet"
           table="Pet" lazy="false">
           <id name="id" column="PET_ID">
           <generator class="native" />
           </id>
           <joined-subclass
           name="Dog"
           extends="Pet"
           lazy="false">
           <key column="PET_ID" />
           </joined-subclass>
           </class>
          </hibernate-mapping>
          


          If I writte that kinds of things, I have an exception due to a duplicate declaration for my class Dog.

          A lot of class inherits from my interface and I'd preferred to use annotation instead of hbm.xml files. Is there a way to mix for the same entity hbm.xml and annotations ?


          • 2. Re: Mixing annotations and hbm.xml
            Bill Burke Master

            no support for XML overrides yet, but you can specify one bean in XML the other in annotations and set up a relationship between the two...

            • 3. Re: Mixing annotations and hbm.xml
              Emmanuel Bernard Master

              you can't mix a hierarchy so far. It's a hard one to do.