I have a master-child tables. User can add/remove childs after selecting the master item/entity. When the master item list selection index changes, I fill the child table/arraylist with child items of this selected master item from the DB. I opened the entity manager, started the transaction, persist or remove child entities/items when the user clicks child add/remove buttons accordingly. My problem is to keep the track of new and removed child entities, while the user selects another master item. Because I am clearing the child table/Arraylist (but not clearing persistence context) before filling it with new selected master item’s child entities. I want to reflect the new/removed, not committed yet child items when the user selects the previous master item again. Hope explained my problem properly. Using hibernate over JPA. Thanks.
I have a master-child tables. User can add/remove childs after selecting the master item/entity.
Share
Well, just execute a query to get all the children of the selected master. Even if the transaction is not committed yet, the transaction sees them in the database, since it has saved them.
Note, however, that using long transactions is not scalable, and will lead to all sorts of locking and staleness problems. Why don’t you save the children and commit each time the user adds or remove a child?