JPA 1.0 Complaints
Recently at work I have been refactoring a project I wrote some time ago to reduce the amount of code. When I initially wrote the program I was just learning the JEE5 stack and had no idea what the difference between lazy/eager loading of relationships was, let alone the concept even existed. Because of my lack of knowledge at the time I wrote a ton of extra code which basically simulated an eager load.
During this refactoring process I have realized that I currently have a few huge pet peeves with JPA.
- If you remove child objects from a parent object in a relationship, when you update (merge) the detached entity instance with the database it doesn’t remove the removed objects from the database, in fact it actually remerges them with the detached instance. Although I understand this is technically what a merge is, it is often quite inconvenient.
- Many to many relationships are a nightmare to manage, it actually is easier to manage the relationships as two one-many relationships. Using two relationships should makes it much more difficult to manage the relationship, however because of the slightly broken implementation thought of for JPA removing a child won’t actually remove the relationship, it will actually attempt to remove the object the relationship is referring to.
- I often find myself having to use EntityManager.refresh() and EntityManager.flush() frequently in my facade classes to ensure that the data is concurrent, I feel that this should be handled by the JPA provider.
Fortunately JPA 2.0 is supposed to contain a @RemoveOrphans annotation which should take care of issue one, however I have yet to hear on the other issues. What has everyone else’s experience been with the quirks of JPA?
Tags: Databases, Development, Java, JPA, Persistence, Software








