简体   繁体   中英

Oracle Flashback Query with Hibernate

I've to use Oracle Flashback Queries in my Java application. We're using Hibernate for data persistence so I'd like to know if there is a way of enable this feature in Hibernate.
Of course I can use SQL queries of Hibernate, but that's not the idea.

So far Hibernate is not supporting this functionality in a native way (as far as I know), but with the mentioned ENABLE_AT_TIME Oracle calll you will be actually able to achive what you want. Be careful though! this will enable the "time machine" for the entire session (that could lead to interesting behaviour in case of connection pooling). Here is a full example on correct usage:

EXECUTE dbms_flashback.enable_at_time('30-AUG-2000');
--your queries go here
SELECT salary FROM emp where name = 'Joe'
EXECUTE dbms_flashback.disable;

Eclipselink is something that supports ("history.as-of") the as of timestamp solution, but you have to set it as a hint . For example:

//...
query.setHint("eclipselink.AS_OF", "2012/10/15 11:21:18.2");
//...

Or you can do it via annotation:

//...
@QueryHint(name=QueryHints.AS_OF, value="2012/10/15 11:21:18.2");
//...

If you have stick to Hibernate you should take a look at the incorporated Auditing with the @Audit annotation. https://docs.jboss.org/envers/docs/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM