Hi Guys,
I have used Hibernate in quite a few projects but I am begining to doubt if Hibernate is the right choice for my current project. We have a very complex hierarchical Jtree which talks to a DAO that uses Hibernate to manage persistence. The Tree consists of Object A which has one to many relationship with itself and many to many with Object B (the entire object graph is much more complex). Since we have short running sessions , managing the detached objects and updating them has become a pain. A typical use case is : We load two Object As in two different sessions. But the Object Bs in these As contain some other Object in their object graph which point to the same database table row(have the same primary key) but since they were loaded in two different sessions they have different Java identities. When I try to add these two As to another A , I get a NonUniqueObjectException because I have two different objects in two different graphs representing the same DB row. My workaround is to navigate to these two objects with same db identity but different java identity and do a session.refresh()/session.get() on these objects in the DAO so that both the objects have same Java as well as DB identity. But I am not very comfortable with this solution as this will force me to use lots of instanceof before doing session.refresh() because Object B has three different subtypes and not all of them will have the same set of such associations. Any suggestions on this particular use case and suitability of Hibernate for complex hierarchical Trees will be much appreciated.
Cheers, Jim
|