How do I override values in Insert or Update query?
610602Jun 5 2008 — edited Jun 9 2008Hello,
I've been researching this for a couple of days, off and on. And now I'm frustrated that I can't find an answer.
The project that I'm working on has a large legacy database running on Oracle10g that currently has a library of legacy code that builds PreparedStatements and handles all of the persistence manually. I'm trying to migrate to using JPA for the bulk of the persistence. My problem is that there are columns on the database that get set with sysdate, the result of a custom function, or even some aggregate value on an insert and/or update.
I feel like I need to override the value that toplink uses in the insert and update statements. For example: (this table and query are completely contrived for the purpose of this example)
TestTable
---------------
Id NUMBER
Name VARCHAR2(50)
LastUpdated DATE
Balance NUMBER
A legacy update would look like:
UPDATE TESTTABLE SET NAME=?, LASTUPDATED=sysdate, BALANCE=CalcBalance(?) WHERE Id = ?
I'd like to tell toplink that when it builds the update query to ignore the value in the LastUpdated and Balance properties and instead use static strings that will make sense to the database.
Is it possible to do this with JPA/Toplink? Maybe an annotation I'm missing? Or a class I can extend?
Thanks for putting up with my rambling,
-Jay