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;
}