[hibernate-dev] Unexpected behavior for @PrePersist/@PreUpdate callback when using EntityManager#merge() on transient object

deepak raut deepak.raut77 at gmail.com
Tue Aug 19 06:50:24 EDT 2014


I have an entity class like -

public class Item {
 @Id
 //mapping
 private Long id;

 @ElementCollection
 //mapping
 private Set<ItemWrapper> wrapperSet;

 @Transient
 private Map<Item, Boolean> itemPredecessor;

..........
..........

 @PrePersist
 @PreUpdate
 private void populateSet() {
    wrapperSet.clear();
    for(Map.Entry<Item, Boolean> entry : itemPredecessor.entrySet()) {
        wrapperSet.add(...);
    }

 }
..............
}

What happens is when I call entityManager.merge(...) with newly
instantiated object with itemPredecessor map having some entries in it.
Hibernate invokes callback method populateSet() with copy of instance
passed to merge() which doesn't contain itemPredecessor map with respective
entries as itemPredecessor is marked @Transient. I am using hibernate
4.3.5. Is this the right behavior?

-- 
Regards,
Deepak A. Raut


More information about the hibernate-dev mailing list