Update entity with many-to-one bidirectional mapping with Hibernate session

Mapping in parent class: (Admin.java)

@OneToMany(fetch = FetchType.LAZY, mappedBy = "admin")
	public Set<Phieuxacnhan> getPhieuxacnhans() {
		return this.phieuxacnhans;

	public void setPhieuxacnhans(Set<Phieuxacnhan> phieuxacnhans) {
		this.phieuxacnhans = phieuxacnhans;

Mapping in child class: (Phieuxacnhan.java)

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "MSCB", updatable=true)
	public Admin getAdmin() {
		return this.admin;

My DAO update admin code: (AdminProcessing.java)

public void saveAdmin(Admin ad) throws  HibernateException, ClassNotFoundException {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction tran = null;
		try {
			tran = session.beginTransaction();
		}catch(Exception e) {
		}finally {

My servlet code:

				Admin admin = df.getAdmin(mscb); // get an admin by admin id
				Phieuxacnhan phieu = df.getPXN(msphieu); // get a phieuxacnhan by phieuxacnhan id
				AdminProcessing ap = new AdminProcessing();

The code run without anr errors or bugs but I do not have any changes in my database.
Thank you for your response !

Show us the mappings and the data access code so we can see what you are doing.

1 Like

@vlad Thanks for responding! I’ve just edited my question with the code in it.

You need to add the generated SQL statements as well so we can see what happens.

Or, try to replicate it with this test case template.

1 Like

@vlad Ohh yes I will add the generated SQL statements and think more about this.
Nothing but thanks !