Failed to delete using eclipselink

1

Good afternoon guys.

I'm giving maintenance to a system that another developer started, before he was using hibernate and then migrated to eclipselink.

When I was using hibernate it was working normal, and when it migrated it started to fail delete.

The Controller looks like this.

@RequestMapping(value = {deletePath}, method = RequestMethod.POST)
public String delete(@PathVariable("id") String id, Division division) {
       divisionService.delete(division);
       return "redirect:"+defaultPath;
}

stackoverflow

  

Error: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: org.postgresql.util.PSQLException: ERROR : null value in column "name" violates not-null constraint Detail: Failing row contains (d1ba96c6-baac-4664-86f1-af22386324bd, AB8D5E1F-66C1-40F9-B98E-DEC21FFA7626, null, null, d1ba96c6-baac-4664-86f1 -af22386324bc, 2015-03-27 11: 42: 27,427, d1ba96c6-baac-4664-86f1-af22386324bc, 2015-03-27 12: 27: 29,097, f). Error Code: 0 Call: UPDATE _login.division SET ACTIVE =?, MODIFIEDBY =?, MODIFIEDON =?, NAME =?, Parent =? WHERE (id =?) Bind = > [false, d1ba96c6-baac-4664-86f1-af22386324bc, 2015-03-27 12: 27: 29.097, null, null, AB8D5E1F-66C1-40F9-B98E-DEC21FFA7626] Query: UpdateObjectQuery (com.xphub.core.model. Division @ 7cc1d214)   URL:

    
asked by anonymous 27.03.2015 / 16:30

1 answer

0

I do not have all the code to say 100% what the problem is, but it seems to me that your DivisionService class is trying to give an update on the Division entity received by the controller.

Probably this system is one that does not actually delete the data, it just changes a flag to disable or disable the record that will no longer be displayed.

When attempting to update the object, probably by calling the merge method, EclipseLink validated the entity again and saw that the data was not populated. This is probably because the controller method receives only the ID and not the other entity fields.

To solve this, it seems to me that the most direct output would first retrieve the original entity so that it contains the necessary fields, like this:

division = divisionService.find(id);
divisionService.delete(division);

In JPA this sort of thing is common. You may not know that an object is only a JPA entity if it is in the JPA context. The Division parameter of your controller method is a common object. It will only be a managed entity if you retrieve the data by EntityManager or if you use merge . However, the latter will replace the registry values in the database with the values of the new object, which in this case are null.

    
27.03.2015 / 17:51