• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

PrePersist doesn't work with Hibernate Template

 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am using Spring's Hibernate template to save the entities.

I tried to use entity callback methods like PostPersist, PreRemove but they are not invoked.

Also, i read somewhere that these methods will work only if we use JPATemplate instead of Hibernate template.

Are there any similar lifecycle methods that we can use while using HibernateTemplate.

Thank you

Rahul
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Rahul,

I'm afraid I don't have a solution for you, but did you find an alternative? I'm trying the same thing, adding a method anotated with @PrePersist but it doesn't get invoked.

Thanks in advance.
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Henrique,

I did not get the solution for it, and had to change my API to accomplish it..

Like in my BaseDAOs for saving the entities, i introduced the callbacks like beforeSave(), afterSave() will null implmentation, and overrode those methods in the DAO of whichever entity i needed to save.

I think there might be a more elegant solution for it, but it satisfied my requirement so, i went ahead with that.

Regards,

Rahul
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it's a bummer. I've just read on some forums that if I use Session instead of EntityManager the callBack Methods don't get invoked. I can't guarantee that programmers will use EntityManager and not Session.

Thanks for your reply and idea, anyway.
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Infact, i am probably not sure about the concept of EntityManager.

Since Hibernate Template is provided by Spring, which uses session internally, probably Spring needs to provide a similar wrapper over Hibernate's EntityManager.

Thanks

Rahul
 
reply
    Bookmark Topic Watch Topic
  • New Topic