hi im using two tables where Table1 refers Table2 by manytoOne annotation

here im using the following code to insert in primary and secondry table 

when the register()  is  called it insert in the database

when the  String edit()  method is called it edit the particular review and 
update the review 

then for second time register()  is called  detached entity passed to persist  
entity.beans.TblReviews  error comes ......


how to over come this 

even i used  em.flush();
  |        em.refresh(tr);

still the error comes how to reoslve this 



@Stateful
  | 
  | @Name("search")
  | public class SearchAction
  |     implements Search,
  |                Serializable
  | {
  |     static final long serialVersionUID = -6536629890251170098L;
  | 
  |     @PersistenceContext
  |     EntityManager em;
  |     
  |     @RequestParameter
  |     BigDecimal id;    
  |   
  |     @RequestParameter
  |     BigDecimal revid; 
  |     
  |   
  |       @Out(required=false)
  |     TblProducts pro;
  | 
  |         @DataModel
  |     private List rev;
  |       
  |     @Out(required=false)
  |     Long rid4comm1;
  |    
  |     @In (required=false)
  |     Identity identity;
  | 
  |     TblReviews tr=new TblReviews();
  |     @In(required=false)
  |     @Out(required=false)
  |     TblUserReviews tblu;
  |     
  |      @Out(required=false)
  |     List<TblUserReviews> editreview;
  |     
  |     @Begin(join=true)
  |     public void selectFromRequest() {
  |             
  |         if (id != null) {
  |                     pro = em.find(TblProducts.class, id);
  |                     details = em.createQuery("select s from SearchBean s 
where s.storeProductId in (select st2.storeProductId from TblProductStore st2 
where st2.productId="+id+")").getResultList();
  |                     rev= em.createQuery("select p from TblReviews p where 
productId="+id+"").getResultList();    
  |                     
  |         }           
  |     }
  |          @Begin(join=true)
  |     public String register() {
  |             tr.setProductId(pro);
  |             tr.setUserId(identity.getUsername());
  |             Set<TblUserReviews> tblUserReviewsCollection= new 
TreeSet<TblUserReviews>();
  |             tblu.setReviewEntryId(tr);
  |             tblUserReviewsCollection.add(tblu);
  |             tr.setTblUserReviewsCollection(tblUserReviewsCollection);
  |             em.persist(tr);
  |             em.flush();
  |             em.refresh(tr);
  |     return "/prodis.xhtml";
  |     }
  |     @Begin(join=true)
  |     public String edit() {
  |     em.merge(tblu);
  |     return "/prodis.xhtml";
  |     }
  |     
  |      @Begin(join=true)
  |     public void editReview(){
  |             editreview= (List<TblUserReviews>) em.createQuery("select p 
from TblUserReviews p where userReviewId="+revid+"").getResultList();
  |             tblu = (TblUserReviews) editreview.get(0);
  |             }
  |     @End
  |     public void reset() {}
  | 
  |     @Destroy 
  |     @Remove
  |     public void destroy() {}
  |     
  | }


thank u regards 
kavi

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4083443#4083443

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4083443
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to