Hibernate onetoone Mapping Issue while saving after Migrating to 5.4

Hello, we have a scenario where we have onetone relation with between three entities. Everything was working fine in Version 3.3 . We had to migrate the version to 5.4. After migration there were Issue revolving onetoone mappings. In this case we have three entities which have onetoone join column mapping between each other. And in the business logic we are saving the entities. After this business logic is completed where we have @Transactional annotation, we need to call one of the above three entities for a update statement. But the problem is when the business logic is completed inside method with @Transactional annotation it should have either commited or rollback the transaction based on success or failure once it came out of the method, but the table lock is not released because of that when the update statement is called a deadlock is happening where the table lock is not released and the spring batch job is not ending, no error is thrown, the final update query got stuck and nothing happens after that. Added the sample code below. Please provide any suggestion on the Issue as it is working properly on the old version.

(Note : This deadlock is happening only when more than one record is inserted/updated for a same parentOrder).

We suspect hibernate is not releasing the table lock or flushing the session once the below logic is completed. once the below part is completed the next sequence of action in the batch Job will try to do an update on Plan details entity.

@Entity
@Table(name = "ORDER_BOOK")
public class FundOrder {
 protected Long orderId;
protected SysOrder OrderSys;

        @Id
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "id_gen")
	@Column(name = "ORDER_ID")
	public Long getOrderId() {
		return orderId;
	}

	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}

	@OneToOne(fetch = FetchType.LAZY,mappedBy="parentOrder", cascade = CascadeType.ALL)
	@JoinColumn(name = "ORDER_ID", insertable = false, updatable = false)
	public SysOrder getOrderSys() {
		return this.OrderSys;
	}

	public void setOrderSys(SysOrder OrderSys) {
		this.OrderSys = OrderSys;
	}

}


@Entity
@Table(name="ORDER_SYS")
public class SysOrder extends WMBaseObject
{
protected Long orderId;
protected PlanDetails planDetails;
    protected Long parentOrderId;
    protected FundOrder parentOrder;

public void setParentOrder(FundOrder parentOrder){
    	this.parentOrder = parentOrder;
    }
    
    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="PARENT_ORDER_ID",insertable=false,updatable=false)
    public FundOrder getParentOrder(){
    	return this.parentOrder;
    }
    
    public void setParentOrderId(Long parentOrderId){
    	this.parentOrderId = parentOrderId; 
    }
    
    @Column(name="PARENT_ORDER_ID")
    public Long getParentOrderId(){
    	return this.parentOrderId;
    }
    public void setPlanDetails(PlanDetails planDetails){
    	this.planDetails = planDetails;
    }
    
    @OneToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ORDER_ID",insertable=false,updatable=false)
    public PlanDetails getPlanDetails(){
    	return this.planDetails;
    }
    
    @Id
    @Column(name="ORDER_ID")
    public Long getOrderId() {
        return orderId; 
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId; 
    }
}


@Entity
@Table(name="PLAN_LIST")
public class PlanDetails{
protected Long orderId;
protected SysOrder orderSys;
public void setOrderSys(SysOrder orderSys){
    	this.orderSys = orderSys;
    }
    
    @OneToOne(fetch=FetchType.LAZY,mappedBy="planDetails")
    @JoinColumn(name="ORDER_ID",insertable=false,updatable=false)
    public SysOrder getOrderSys(){
    	return this.orderSys;
    }

	@Id
	@Column(name="ORDER_ID")
	public Long getOrderId() {
		return orderId;
	}

	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}
}

//Business logic Method
@Transactional
public boolean saveOrder(FundOrder fOrder,SysOrder orderSys){
//Business logic
     fOrder = fundOrderDao.saveOrder(fOrder);
	            	orderSys.setOrderId(fOrder.getOrderId());
	            	SysOrderDao.saveFOrderSys(orderSys);

                      //Business logic
                        fOrder = fundOrderDao.saveOrder(fOrder);
	            	orderSys.setOrderId(fOrder.getOrderId());

                        //Saving/updating PlanDetails entity
                        planDetails  = planListManager.get(orderSys.getParentOrderId());
                        planListDao.saveplanDetails(planDetails);


}

Hello, Hibernate version 5.4 is no longer supported. From what I can see there’s nothing wrong with your mappings, though from the little code you pasted here it’s not clear what the DAOs are doing when persisting entities. I strongly suggest upgrading to a newer version if you need support from the community, and if the issue persists please report back and we’ll be happy to help.

Here you can find details about currently supported versions and commercial support options.

Hello, Thank you for your suggestion. We’ll upgrade to a newer version. I will accept your solution for now. If the Issue persists I will come back, Thank you.