Short version: Is there a way to tell JPA to ignore null properties of a detached entity instance when merging?
Long version:
I Have the following scenario:
Web Application communicates through HTTP REST with Backend. Backend uses JAX-B, JAX-RS, EJBs and JPA2.0 (EclipseLink). Application functionality is basically CRUD.
Because of this design, all entities received through JAX-RS are detached entities, causing JPA to replace all attributes and relationships (if a relationship is null when received, JPA deletes the relationship in the database)
The idea is, having a @OneToMany
unidirectional aggregation relationship between A and B A<>---B
(this creates a join table), I want to modify attributes owned by A
, keeping it's references to B
unmodified. In order to do this I'm doing the following:
- Fetching
A
through JAX-RS, with all it's attributes and references. - Modifying record in web application.
- Sending new values through JAX-RS.
- Merging new deserialized entity (in a detached state).
The issue is, as the application grows, A
get new relationships and data transfered will keep growing with it (and not being required for A
's CRUD operations.
I'm aware that a solution would be to fetch from database the unmodified record and merge it in code, but I'm looking for a solution that avoids this extra database query.