1 Reply Latest reply on Nov 28, 2005 7:13 AM by epbernard

    Cannot usde anything but GeneratorType.TABLE with @Embeddabl

    mge101

      Hi,

      This is a newbie posting so I felt it was better to start here than in jira.

      I am trying to set up a schema where all my main objects can have comments attached.

      The three main classes involved are ;

      =============================================
      @Entity(access = AccessType.FIELD)
      @EmbeddableSuperclass(access = AccessType.FIELD)
      @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
      public class Persistable implements Serializable
      {

      @Id(generate = GeneratorType.TABLE)
      @Column(name = "ID") // mapped in empty SUPERCLASS table
      private int id = -1;

      @OneToMany(cascade=CascadeType.ALL,mappedBy="commented")
      private Set comments = new HashSet();



      public int getId() { return this.id; }
      public void setId(int id) { this.id = id; }

      public Set getComments()
      {
      return comments;
      }

      public void setComments(Set comments)
      {
      this.comments = comments;
      }
      }



      @Entity(access = AccessType.FIELD)
      @Table(name = "Participant")
      @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
      public class Participant extends Persistable
      {

      private String _title;

      private String _firstName;

      private String _middleNameOrInitial;

      private String _lastName;

      @OneToMany(cascade=CascadeType.ALL,mappedBy="participant")
      protected Set _bookings=new HashSet();


      public Participant() {}


      public String getFirstName()
      {
      return _firstName;
      }

      public void setFirstName(String firstName)
      {
      this._firstName = firstName;
      }

      public String getLastName()
      {
      return _lastName;
      }

      public void setLastName(String lastName)
      {
      this._lastName = lastName;
      }

      public String getMiddleNameOrInitial()
      {
      return _middleNameOrInitial;
      }

      public void setMiddleNameOrInitial(String middleNameOrInitial)
      {
      this._middleNameOrInitial = middleNameOrInitial;
      }

      public String getTitle()
      {
      return _title;
      }

      public void setTitle(String title)
      {
      this._title = title;
      }


      public Set getBookings()
      {
      return _bookings;
      }

      public void setBookings(Set bookings)
      {
      _bookings = bookings;
      }
      }




      @Entity(access = AccessType.FIELD)
      @Table(name = "Comment")
      @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
      public class Comment extends Persistable implements Serializable
      {

      private String _comment=null;
      private long _priority=-1;
      private String _title=null;

      @ManyToOne(optional=true)
      protected Persistable commented=null;

      public Comment()
      {
      }

      public Comment(String title, int priority , String comment)
      {
      this._title = title;
      this._priority = priority;
      this._comment = comment;
      }
      public String getComment()
      {
      return _comment;
      }
      public void setComment(String comment)
      {
      this._comment = comment;
      }
      public long getPriority()
      {
      return _priority;
      }
      public void setPriority(long priority)
      {
      this._priority = priority;
      }
      public String getTitle()
      {
      return _title;
      }
      public void setTitle(String title)
      {
      this._title = title;
      }

      public Persistable getCommented()
      {
      return commented;
      }
      public void setCommented(Persistable p_commented)
      {
      this.commented = p_commented;
      }
      }
      =============================================

      Using GeneratorType.TABLE works but gives me duplicate ID's in the object tables which causes problems with comments.

      Using any other GeneratorType gives me illegal SQL when creating the tables in mySql or a run time error when adding a comment.

      Changing Comment so it is not a subclass, disallowing comments on comments, does not seem to make any difference.

      I've tried this with hsqldb, mySql and postgresql. If the error messages for any combination of GeneratorType and database would help I can post them.