• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Latest update of an entity

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We need to keep track of the latest update time of an entity. I know that can be achieved using an entity like this one:


But what if this Entity class has a collection with other child entities and a change (add, update, remove) of one of these child entities should also result in an update of the latestUpdate property. Can this be achieved using only JPA or should I just set the latestUpdate property in the appropriate business methods?
 
Claude Moore
Ranch Hand
Posts: 828
7
IBM DB2 Java Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not an expert of JPA, would it be possible to add, to each entity involved, a non persistent callback handler class ? I mean, for example, something like this :



and then notifiy in the proper set method of Son class the callback.

BTW: I guess this is a fool idea...


 
Claude Moore
Ranch Hand
Posts: 828
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this web page is described something very close to what you need..
Hope this may help.....
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Claude Moore wrote:In this web page is described something very close to what you need..
Hope this may help.....

Maybe I'm missing something, but I don't see what part is very close to what I need. Besides that LastUpdateListener which is equivalent to what I have in OP.
 
Claude Moore
Ranch Hand
Posts: 828
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you're right... I was too superficial in reading that article, I beg your pardon.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Claude Moore wrote:No, you're right... I was too superficial in reading that article, I beg your pardon.

Not a problem, but also no cow
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Roel

Having a quick browse, it seems EclipseLink has a solution for this:

https://dev.c-ware.de/confluence/plugins/servlet/mobile#content/view/18645007

http://www.repix.ch/blog/jpa-how-to-find-out-changes-in-an-entity/

Can't find a solution for any other JPA provider though. Which one are you using?
 
Claude Moore
Ranch Hand
Posts: 828
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote: Not a problem, but also no cow

That's right. ...
... and I think that I'd better study JPA. Seems cool.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another possibility, this time using Hibernate:

http://duckranger.com/2012/12/capturing-property-changes-with-spring-jpa-and-hibernate/
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Boswell wrote:Can't find a solution for any other JPA provider though. Which one are you using?

We are using Hibernate as our JPA provider. I am actually hoping for some standard JPA way, but it seems that's not going to happen
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also wondering if it's not a possibility to have a @Version column using a timestamp instead of a numeric. It seems that's supported by JPA, but I don't know if a new timestamp is written when a child entity changes.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I don't believe there is a JPA-only way of achieving this Roel.

Like with a lot of things in this area, you usually have to go down the provider specific route. Good question though, got me thinking.

Been using JPA and Hibernate for the last 3 years now and this problem has never arisen in my projects. Would be a cool feature. I'm currently using Hibernate auditing (Envers) but I don't think it captures what specifically changed in different revisions of an entity and again, this is provider specific.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel

With regards to @Version, this discussion might interest you:

http://stackoverflow.com/questions/5258585/jpa-version-behaviour
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic