0 Replies Latest reply on Sep 10, 2007 9:20 AM by kavi arasu

    inserting value in mapped colom

    kavi arasu Newbie

      hi im using thre tables table 1 which is a primary table which has two secondry tables table 2 and table 3
      i want to insert the values to the secondry table table3 which colom is mapped to primary table using manyto one annotation

      Table structure
      Table1
      1)Productid
      2)ReviewId-primary key

      table3
      1)Commentid---primarykey
      2)reviewid--mapped with primary table
      3)comments
      table2
      1)userentryid------primarykey
      2)2)reviewid--mapped with primary table

      i want to insert value in table3 only where the commentid is autogenerated
      and userid is get from the session
      but i cant able to set review id because it is mapped as oblect
      how to insert the value

      the example code is

      @Table(name="TBL_REVIEWS")
      public class TblReviews implements Serializable {
       @Id
       @GeneratedValue(generator="SeqID")
       @SequenceGenerator(name="SeqID",sequenceName="TBL_REVIEWS_SEQ",allocationSize=1)
       @Column(name="REVIEW_ENTRY_ID")
       private Long reviewEntryId;
      
      @OneToMany(mappedBy="reviewEntryId",fetch=FetchType.EAGER,cascade={CascadeType.ALL})
       private Set<TblComments> tblCommentsCollection;
      
      
      public Set<TblComments> getTblCommentsCollection() {
       return this.tblCommentsCollection;
       }
      
       public void setTblCommentsCollection(Set<TblComments> tblCommentsCollection) {
       this.tblCommentsCollection = tblCommentsCollection;
       }
      //other getters and setters



      @Table(name="TBL_COMMENTS")
      @Name("tblcomm")
      public class TblComments implements Serializable {
       @Id
       @GeneratedValue(generator="SeqID")
       @SequenceGenerator(name="SeqID",sequenceName="TBL_COMMENTS_SEQ",allocationSize=1)
       @Column(name="COMMENTS_ID")
       private Long commentsId;
      
      private String comments;
      @ManyToOne
       @JoinColumn(name="REVIEW_ENTRY_ID")
       private TblReviews reviewEntryId;
      //other getters and setters
      
      public TblReviews getReviewEntryId() {
       return this.reviewEntryId;
       }
      
       public void setReviewEntryId(TblReviews wEntrreviewEntryIdyId) {
       this.reviewEntryId = wEntrreviewEntryIdyId;
       }



      when i try the code like this


      @In(required=false)
       TblReviews tr=new TblReviews();
      
      @In(required=false)
       TblComments tblcomm;
       @Out(required=false)
       @RequestParameter
       Long rid4comm; (review entry id value)
      
      public void writeComment() {
      tblcomm.setReviewEntryId(tr);
      em.persist(tblcomm);
      }


      it inserting the other values except reviewentryid in secondry table
      how to achive it
      thank u regards
      kaviarasu