4 Replies Latest reply on Aug 15, 2005 4:53 PM by Goran Ehrsson

    @EmbeddableSuperclass does not works as expected !

    Mihail G. Meleca Newbie

      @EmbeddableSuperclass does not works as described in JSR220 Java Persistence API (Public Draft, June 25, 2005).

      Chapter 2.1.9.3 contains description of very usefull (for us) annotation @EmbeddableSuperclass for classes "which provides persistent entity state and mapping information, but which is not itself an entity".

      After some experiments we have understood, that @EmbeddableSuperclass works only if the class is also annotated using @Entity, that leads to creation of the undesirable table in a database.

      Is this situation Ok ?

        • 1. Re: @EmbeddableSuperclass does not works as expected !
          Emmanuel Bernard Master

          Hum, this is a limitation we have currently.
          You need to explicitly list your embedded superclasses in your persistence.xml

          FYI I fixed that in Hibernate Annotation HEAD a couple of days ago.

          • 2. Re: @EmbeddableSuperclass does not works as expected !
            Philipp Meier Newbie

             

            "epbernard" wrote:

            You need to explicitly list your embedded superclasses in your persistence.xml


            I'm using 4.0.3RC1 and have the same problem. I tried your tip but it fails. This is the persistence.xml I have:

            <entity-manager>
             <class>foo.EmbeddedSuperClass</class>
            </entity-manager>
            


            Where EmbeddedSuperClass is

            @Embeddable
            @EmbeddableSuperclass
            public class EmbeddableSuperClass implements java.io.Serializable {
            
            ...
            }


            and DerivedClass is

            @Entity
            @Inheritance(strategy=InheritanceType.JOINED)
            public class DerivedClass extends EmbeddableSuperClass implements Serializable{
            ...
            }


            But the properties derived from EmbeddableSuperClass are note created in the database. Is there a "conflict" because EmbeddableSuperClass is used as a @EmbeddableClass and a @Embeddable?

            This kind of hierachy is driven by the following design. I have some global types which act as a default value and which are used as embedded instantec as well as in many-to-one relations. An example would be contract detail. In each order instance I have a reference to a "GlobalContractDetail" which is an instance of a ContractDetail and a used contract detail which store a snapshop of the GlobalContractDetail used a time of creation of the order. In my usecase I have a hierachie of ContractDetail. So the actual class model is:

            @Embeddable, @EmbeddableSuperClass ContractDetail with basic properties.
            @Entity GlobalContractDetail extends ContractDetail which adds a PK to ContractDetail
            Order has a @many-to-one to GlobalContractDetali and a @embedded ContractDatail which stores the snapshot.

            • 3. Re: @EmbeddableSuperclass does not works as expected !
              Emmanuel Bernard Master

              This is a known bug, will be fixed for the next release, I hope.

              • 4. Re: @EmbeddableSuperclass does not works as expected !
                Goran Ehrsson Newbie

                I could not get @EmbeddableSuperclass to work at all with 4.0.3RC1, but with 4.0.3RC2 things started to work. I use property access on my entities.
                So from my point of view it is fixed in RC2.
                This is how I use it.

                @EmbeddableSuperclass(access = AccessType.PROPERTY)
                public abstract class BasicEntity implements Serializable {
                 private Long id = null;
                 private int version = 0;
                
                 @Id(generate = GeneratorType.AUTO)
                 public Long getId() { return this.id; }
                 public void setId(Long id) { this.id = id; }
                
                 @Version
                 public int getVersion() { return this.version; }
                 public void setVersion(int version) { this.version = version; }
                }
                
                @Entity(access = AccessType.PROPERTY)
                public class User extends BasicEntity { ... }