I believe these annotations only works when you're using JPA. Matt
On 12/18/07, Rob Hills <[EMAIL PROTECTED]> wrote: > Hi Again, > > I spoke too soon on this one. I thought the timestamping was working, but > then discovered it was being done by > some code I'd put into a base dao a little while back. AFAICT, the > @EntityListeners and @PrePersist annotations > seem to be totally ignored by the version of Hibernate in AppFuse 2.0, which > is a real shame as they promise very > useful functionality. > > On 17 Dec 2007 at 23:55, Rob Hills wrote: > > > WooHoo! I found a JPA/Hibernate "Event Listener" solution for this, and it's > > really easy. As is often the way, I stumbled across it while looking for > > something else. > > > > I found the solution here: > > > > http://www.theserverside.com/tt/articles/article.tss?l=JPAObjectModel > > > > Although the article has an unlikely-looking title, search for the string > > "@EntityListeners" and you'll find the first of three code examples showing > > how to add auditing for Created date/time, Updated date/time and the user > > making the changes. The keys are the JPA @EntityListeners and > > @PrePersist JPA tags (also supported by Hibernate. It took me less than 5 > > minutes to get it all working (though I already had a base class for all my > > entities and it already had a lastUpdated attribute, so that made it > > easier). > > > > On 14 Dec 2007 at 9:54, Rob Hills wrote: > > > > > Matt Raible wrote: > > > > Have you thought about doing this with a trigger in your database? Do > > > > you need to record the user's information along with this auditing? > > > > I've done this with Event Listeners in the past. > > > > > > > I'd be quite comfortable with doing it as a trigger, but for > > > "political" reasons that could be a bit tricky (though not impossible). > > > I just thought that because it's such a common pattern, Hibernate would > > > have a solution for it, but I guess it doesn't. > > > > > > I've not played with event listeners yet, in general terms what event > > > would you hang one onto to do this kind of thing. WRT recording users > > > information, there's nothing in the spec about that, but from what I > > > know of the client, I can see that requirement arising sooner or later. > > > > On 12/13/07, Rob Hills <[EMAIL PROTECTED]> wrote: > > > > > > > >> Hi All, > > > >> > > > >> I'm using AppFuse 2.0 + Struts2 + Hibernate. > > > >> > > > >> I need to timestamp all of my persisted data. > > > >> > > > >> I have a base model class that includes a "lastUpdated" attribute and I > > > >> was hoping to be able to annotate it with something that would tell > > > >> Hibernate to timestamp it whenever it was saved to the DB, much as you > > > >> would do with an "After Update" trigger. > > > >> > > > >> I've been hunting through the Hibernate documentation to see if it has > > > >> any "automatic" way of doing this, but haven't turned up anything > > > >> obvious. Hibernate has an @Temporal annotation, but AFAICT, it simply > > > >> provides a direction about the persisted datatype. > > > >> > > > >> Is there any way to "automate" this or will I have to do it myself in > > > >> the DAO? If I have to do it myself in the DAO, I assume the most > > > >> efficient way will be to have a base DAO class that sits between > > > >> GenericDao and my own Dao's and have it do the timestamping > > > > Hope this helps someone else one day. > > Cheers, > Rob Hills > Waikiki, Western Australia > Mobile +61 (412) 904-357 > Fax: +61 (8) 9529-2137 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
