Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / August 2003

Tip: Looking for answers? Try searching our database.

Trigger on EJB Entity Bean when persisting

Thread view: 
David Smith - 30 Jul 2003 13:24 GMT
Hello,

I need to do versioning of data, where the current record is stored in
one database table and the old records are stored in another table.
I'm using EJB entity beans.

What's the best way to do this moving of the old data into the history
table and putting the new data into the current table?

Something like a trigger at the EJB level when the object is
re-persisted is probably what I'm looking for, but if the container
caches the data then there's no guarantee as to when this would
happen.

Does anyone have any thoughts on this, please?

Thanks,
David.
Marek Lange - 31 Jul 2003 20:55 GMT
David Smith schrieb:
> Hello,
>
[quoted text clipped - 11 lines]
>
> Does anyone have any thoughts on this, please?

This is hard to do due to the caching of the EJB Container. You should
try to switch off the caching completely to achieve constant validity of
the entity bean data. You could try to trigger the operations in the
ejbStore() method when the container synchronizes the data to the db.

-marek
dspublic-REMOVE THIS AND HYPENS- - 02 Aug 2003 07:56 GMT
Te common pratice for this is to allow it to happen at the DB level.
Have your dba's set up a trigger to write the record to a history or
audit table
Don Stacy

>David Smith schrieb:
>> Hello,
[quoted text clipped - 19 lines]
>
>-marek
Klas - 06 Aug 2003 15:48 GMT
This is, I think, is not a recommended solution. Switching of the cache does
more harm than good.

/Klas

> David Smith schrieb:
> > Hello,
[quoted text clipped - 19 lines]
>
> -marek
Marek Lange - 07 Aug 2003 09:34 GMT
> This is, I think, is not a recommended solution. Switching of the cache does
> more harm than good.

Agreed. Cache is king. As someone has written in another post before,
EJB is not the recommended solution for the problem.

-marek
Klas - 06 Aug 2003 13:19 GMT
First, it might be a better solution to keep all the records in the same
table with a version number?

Otherwise...I suppose you have som type of facade in form of a stateless
session bean which performs the create, remove, update, delete of the
entity? If not then you should definately thinking about refactoring and
build one. If you have one then it's easy (I'll use a person as example):
a) find the 'Person' entity that is going to be archived.
b) create a new 'ArchivedPerson' entity and fill it with the values from the
'Person' entity and additional data.
c) create a new 'Person' entity and fill it with the new values.
d) you are done.

/Klas

> Hello,
>
[quoted text clipped - 14 lines]
> Thanks,
> David.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.