-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SaveorUpdate() causing merging of previous and current entry
PostPosted: Wed Dec 01, 2010 12:59 pm 
Newbie

Joined: Wed Dec 01, 2010 12:50 pm
Posts: 1
Hi
I am new to hibernate.I found particular problem while working with attachdirty() stuff.
My links is a collection , which is being obtained from a form bean and when i process my form bean(service method defined below)
and say attachdirty(*); in attach dirty i am using saveorUpdate() this saveorupdate() is causing merging and of pervious entries and my current form bean data rather than updating database with my current form bean entries

my service method

Code:
public String EditProject(ProjectEditInfoBean projEdit){
      String result="";
      String[] newlangs , newlinks;
      
      Projects proj = findProject(projectsDao.findByName(projEdit.getProjName()));
      proj.setDescription(projEdit.getProjDesc());
      proj.setNotes(projEdit.getNotes());
      
      
      // this for updating links
      //****************************************
      newlinks=getLangList(projEdit.getLinks());
      Set<Links> l = new HashSet();
      for(int i = 0; i < newlinks.length; i++){
      Links link = new Links();
      link.setLinks(newlinks[i]);
      link.setProjects(proj);
      l.add(link);
      }
      proj.setLinkses(l);
   
      
      
      //for processing languages
      newlangs = getLangList(projEdit.getSelectlang());
            for(String lang:newlangs)
         projlangDao.save(new     ProjLang(findProject(projectsDao.findByName(projEdit.getProjName())),findLanguage(proglangDao.findByName(lang))));
      
      
      projectsDao.attachDirty(proj);
      
      return result;
   }


My Dao
Code:
   public void attachDirty(Projects instance) {
      log.debug("attaching dirty Projects instance");
      Transaction tx=null;
      Session session=getSession();
      try {
         tx=session.beginTransaction();
      
         //hibernateTemplate.saveOrUpdate(instance);
         
         session.saveOrUpdate(instance);
         session.refresh(instance);
         tx.commit();
         closeSession();
         
         log.debug("attach successful");
      } catch (RuntimeException re) {
         log.error("attach failed", re);
         throw re;
      }

   }


my model part for links
Code:
   
   @OneToMany( cascade = CascadeType.ALL, mappedBy = "projects",fetch=FetchType.EAGER)
   public Set<Links> getLinkses() {
      return this.linkses;
   }

   public void setLinkses(Set<Links> linkses) {
      this.linkses = linkses;
   }
   


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.