3 Replies Latest reply on Nov 17, 2005 6:36 AM by Emmanuel Bernard

    Embeddable superclass and relationships.

    Bogdan Daniliuc Newbie

      Hi,

      We are trying to define a OneToMany relationship between an embeddable superclass and another entity.

      @EmbeddableSuperclass(access = AccessType.FIELD)
      public abstract class Base {
      ....
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "objectId")
      protected List<AuditEntry> auditList;
      ....
      }


      In AuditEntry we have a field objectId of type Long (Since the Base class is embeddable we cannot use it on the other side of the relationship). Finally we have a class that extends from Base:

      @Entity(access = AccessType.FIELD)
      public class BasicItem extends Base implements Serializable {
       ...
      }


      The result of deploying the application is that the table generated for AuditEntry has an objectId field that has foreign key constraint that references the BasicItem id.

      List<AuditEntry> auditList= new ArrayList<AuditEntry> ();
      AuditEntry au= new AuditEntry();
      auditList.add(au);
      basicItem.setAuditList(auditList);
      em.persist(basicItem);


      Running the above test program results in the auditEntry being inserted into database, but with an empty objectId field.

      What are we doing wrong? We can set the value manually but is there a way to make the update on objectId field automatic?

      Bogdan