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