-->
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.  [ 2 posts ] 
Author Message
 Post subject: Cascade deletes but does not SAVE
PostPosted: Sun Oct 05, 2014 2:15 pm 
Newbie

Joined: Thu Sep 25, 2014 9:30 am
Posts: 2
UserprojectEntity has a OnetoMany relation with LinereferenceEntity. Session.delete deletes Linereference records. But session save does not add Linereference records.

UserprojectEntity code:


@XmlElementWrapper(name = "linereferencelist")
@OneToMany(targetEntity =LinereferenceEntity.class, mappedBy = "upl")
@Cascade(CascadeType.ALL)
@OrderBy("id ASC")
public Collection<LinereferenceEntity> getLinereference() {
return linereference;
}

public void setLinereference(Collection<LinereferenceEntity> linreference) {
this.linereference = linreference;
}


LinereferenceEntity code:


private UserprojectEntity upl;
@XmlTransient
@ManyToOne
@JoinColumns({@JoinColumn(name = "user", referencedColumnName = "user", nullable = false,insertable = false,updatable = false), @JoinColumn(name = "project", referencedColumnName = "project", nullable = false,insertable = false,updatable = false)})
public UserprojectEntity getUpl() {
return upl;
}

public void setUpl(UserprojectEntity upl) {
this.upl = upl;
}
}

Calling program. obj is a UserprojectEntity
private void saveRecords(String sConfig, Object obj){
SessionFactory sessionFactory = commonFuncs.getSessionFactory(sConfig) ;

Session session = sessionFactory.openSession();
Transaction transaction;
transaction = session.beginTransaction();


session.save(obj);

transaction.commit();
session.close();

}

private void deleteRecords(String sConfig, String sDelstring){
SessionFactory sessionFactory = commonFuncs.getSessionFactory(sConfig) ;

Session session = sessionFactory.openSession();
Transaction transaction;

transaction = session.beginTransaction();

Query q = session.createQuery(sDelstring);

Object upe = q.list().get(0);
session.delete(upe);
transaction.commit();
session.close();

}


Top
 Profile  
 
 Post subject: Re: Cascade deletes but does not SAVE
PostPosted: Sun Oct 12, 2014 12:03 pm 
Newbie

Joined: Thu Sep 25, 2014 9:30 am
Posts: 2
I needed to use merge


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

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.