0 Replies Latest reply on Feb 13, 2007 7:14 PM by cfrostrun

    JPA-Hibernate  Parent/Child Relationship within Same Object

    cfrostrun Newbie

      Does anybody have an idea where I'm going wrong...

      here's my table structure for Comment

      id | integer | not null
      website_id | integer | not null
      event_id | integer | not null
      parent_id | integer |
      title | character varying(150) |
      post_date | timestamp without time zone |
      user_id | integer | not null
      ip_address | character varying(100) |
      comment_name | character varying(100) |
      comment_email | character varying(100) |
      hyperlink | character varying(200) |
      comment | text |
      score | integer | not null
      active_flag | character(1) |


      Parent Id is referencing Comment.Id ..

      Here's my JPA Domain Object

      @Entity
      @Table(name="comments", schema="eventservices")
      public class Comment implements IDomainObject{

      @Id
      @GeneratedValue(generator="SequenceComments")
      @SequenceGenerator(name="SequenceComments", sequenceName="eventservices.seq_comments")
      private long id = 0;

      @Column(name="website_id")
      private long websiteId = 0;

      @OneToMany(targetEntity=Comment.class, mappedBy="parent", fetch=FetchType.LAZY)
      private Collection comments = null;

      @ManyToOne
      @JoinColumn(name="event_id")
      private Event event = null;

      @ManyToOne
      @JoinColumn(name="parent_id")
      private Comment parent = null;

      @Column(name="title")
      private String title = null;

      @Temporal(TemporalType.TIMESTAMP)
      @Column(name="post_date")
      private Date postDate = null;

      @Column(name="user_id")
      private long userId = 0;

      @Column(name="comment_name")
      private String commentName = null;

      @Column(name="comment_email")
      private String commentEmail = null;

      @Column(name="hyperlink")
      private String hyperlink = null;

      @Column(name="comment")
      private String note = null;

      @Column(name="score")
      private long score = 0;

      @Column(name="active_flag")
      private String activeFlag = null;

      @Column(name="ip_address")
      private String ipAddress = null;

      public String getIpAddress() {
      return ipAddress;
      }

      public void setIpAddress(String ipAddress) {
      this.ipAddress = ipAddress;
      }

      public String getActiveFlag() {
      return activeFlag;
      }

      public void setActiveFlag(String activeFlag) {
      this.activeFlag = activeFlag;
      }

      public Event getEvent() {
      return event;
      }

      public void setEvent(Event event) {
      this.event = event;
      }

      public String getHyperlink() {
      return hyperlink;
      }

      public void setHyperlink(String hyperlink) {
      this.hyperlink = hyperlink;
      }

      public long getId() {
      return id;
      }

      public void setId(long id) {
      this.id = id;
      }

      public String getNote() {
      return note;
      }

      public void setNote(String note) {
      this.note = note;
      }

      public Comment getParent() {
      return parent;
      }

      public void setParent(Comment parent) {
      this.parent = parent;
      }

      public Date getPostDate() {
      return postDate;
      }

      public void setPostDate(Date postDate) {
      this.postDate = postDate;
      }


      public String getCommentEmail() {
      return commentEmail;
      }

      public void setCommentEmail(String commentEmail) {
      this.commentEmail = commentEmail;
      }

      public String getCommentName() {
      return commentName;
      }

      public void setCommentName(String commentName) {
      this.commentName = commentName;
      }

      public String getTitle() {
      return title;
      }

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

      public long getUserId() {
      return userId;
      }

      public void setUserId(long userId) {
      this.userId = userId;
      }

      public long getWebsiteId() {
      return websiteId;
      }

      public void setWebsiteId(long websiteId) {
      this.websiteId = websiteId;
      }

      public long getScore() {
      return score;
      }

      public void setScore(long score) {
      this.score = score;
      }

      public Collection getComments() {
      return comments;
      }

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

      public void addComment(Comment comment){
      if(this.comments==null){
      this.comments = new java.util.HashSet();
      }
      this.comments.add(comment);
      }
      }


      Here's the exception in the logs:

      22:12:23,367 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
      22:12:23,367 ERROR [JDBCExceptionReporter] Batch entry 0 insert into eventservices.comments (website_id, event_id, parent_id, title, post_date, user_id, comment_name, comment_email, hyperlink, comment, score, active_flag, ip_address, id) values ( was aborted. Call getNextException() to see the cause.
      22:12:23,367 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 22003
      22:12:23,368 ERROR [JDBCExceptionReporter] ERROR: integer out of range


      Parent Id will be null if it's a top level comment, and in the junit i'm running this is the case... So I don't understand why this isn't working?

      Thanks In Advance,

      Chris