If you have worked with persistence in Java, and the chances are very high that you have worked, you probably know that it is the responsibility of the developer to manually take care of the bidirectional relationships between the entities.
As the JPA specification mandates:
It is the developer’s responsibility to keep the in-memory
references held on the owning side and those held on the inverse
side consistent with each other when they change.
Furthermore:
It is particularly important to ensure that changes to the
inverse side of a relationship result in appropriate updates on
the owning side, so as to ensure the changes are not lost when
they are synchronized to the database.
The above means that the developer will need to handle and update the references between the entities himself, instead of primarily focusing in business logic implementations.
It would be nice for the persistence provider or some utility library to take care of the wirings and re-wirings of the entity reference relationships and let the developer to focus on the business logic.
Most importantly, by moving away this responsibility from the developer, you’re moving away the potential of introducing bugs and inconsistencies in your code.
JpaToolbox is just the library that does the above. This simple lightweight library came out as a by-product of the first time I encountered the situation to manually take care of the entity relationships.
I have been using it since in my projects. Hope you will find it useful too.
Take a look at the following links for complete usage, code and explanation of the JpaToolbox library:
Google Code Project Page
User Guide (HTML, PDF)
Browse Source Code

