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

Gail Badner gbadner at redhat.com
Wed Aug 20 17:16:20 EDT 2014


Hi Deepak,

Please use the user forum (https://forum.hibernate.org/) to discuss your particular case. If after refining your description of the issue you believe it is a bug, then create a Jira issue.

Thanks,
Gail

----- Original Message -----
> From: "deepak raut" <deepak.raut77 at gmail.com>
> To: hibernate-dev at lists.jboss.org
> Sent: Tuesday, August 19, 2014 4:11:00 AM
> Subject: Re: [hibernate-dev] Unexpected behavior for @PrePersist/@PreUpdate callback when using EntityManager#merge()
> on transient object
> 
> Forgot to mention :-
> in case of calling persist(), hibernate doesn't invoke callback method with
> copy object but the actual object passed to persist(); so for persist() it
> works correctly.
> 
> 
> On Tue, Aug 19, 2014 at 4:20 PM, deepak raut <deepak.raut77 at gmail.com>
> wrote:
> 
> > 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
> >
> 
> 
> 
> --
> Regards,
> Deepak A. Raut
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
> 


More information about the hibernate-dev mailing list