1

I'm implementing spring boot rest api application to push data into DB. I have exposed a PUT method which gets parent object and trying to push it directly into DB using hibernate.

Department_T - Parent Object
Employee_T - Child Object

//Department_T
@Id
@Column(name="DEPARTMENT_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private BigDecimal dept_Id;

@OneToMany(fetch=FetchType.LAZY,
cascade= CascadeType.ALL,
mappedBy = "department")
private List<Employee_T> employee= new ArrayList<Employee_T>();

//Employee_T
@Id
@Column(name="EMPLOYEE_ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private BigDecimal emp_id;

@ManyToOne(cascade= CascadeType.ALL, fetch = FetchType.LAZY, optional = false)
@JoinColumn(name="DEPARTMENT_ID", nullable = false)
private Department_T department;

//DAO Class
@Override
public void updateDepartment(Department_T dept) {
   // get the current hibernate session
   Session currentSession = entityManager.unwrap(Session.class);        
   // save scheduler
   currentSession.saveOrUpdate(dept);
 }

//REST Class   
@PutMapping("/update-department")
public Department_T updateDepartment(@RequestBody Department_T dept) {      
    scheduler.updateDepartment(dept);       
    return dept;
}

When i execute in POSTMAN, getting below exception

"error": "Internal Server Error",

"message": "JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is weblogic.transaction.RollbackException: setRollbackOnly called on transaction",

I'm getting payload as a single object(Parent Object, which contains Child Object) & trying to save it in DB. I have checked the code and everything looks fine. If i remove child list from payload, and pass only parent row it commits fine.

Please help.

Regards Raj

Mandar Dharurkar
  • 267
  • 1
  • 5
  • 16
Raj
  • 55
  • 11

0 Answers0