3 Replies Latest reply on Jul 15, 2009 2:49 AM by Adam Warski

    Mimic Envers with JDBC?

    Jamie Bisotti Newbie

      Adam,

      For deletes, we use straight JDBC, instead of Hibernate, for performance purposes. I'd like to have an audit/history here as well. I thought about manually performing the inserts into the audit/history tables, but I wasn't sure if it would work.

      1. How does Envers track the REV?
      - Does it query the REVINFO table each time (in which case I could do that too)?
      - Or, does it cache that value (in which case, how could I let it know it needs to increment it)?

      2. Does Envers do any other caching that straight JDBC update might mess up?

      Thanks,
      Jamie

        • 1. Re: Mimic Envers with JDBC?
          Adam Warski Master

          Hello,

          how the revision number is generated depends on your database and how you define your revision entity. In mysql it's an auto_increment field by default, but you can use sequences, table generators etc, if you define the @GeneratedValue properly in the revision entity.

          There's no any additional caching that Envers does. It uses Hibernate in the background so any caching can be configured there.

          I guess you can safely and easily insert the data into the audit tables manually :).

          Adam

          • 2. Re: Mimic Envers with JDBC?
            Jamie Bisotti Newbie

            Adam,

            I'm using Firebird as my database.
            I'm not currently defining my revision entity; just using the default -- though it sounds like I'll need to???

            The part I'm currently confused about is the insertion into the REVINFO table. If I do not create my own revision entity, what class do I need to instantiate/populate? Or, do I have to specify my own revision entity?

            Where does this code live in the Envers packages? The code that does the default way.

            Thanks for all the help!

            Jamie

            • 3. Re: Mimic Envers with JDBC?
              Adam Warski Master

              Hello,

              in many cases using the default will work. I don't know what's the default id generation in firebird, so hard to say :). The default revision entity is in the "DefaultRevisionEntity" class :).

              Normally, you just need to insert a new row into the REVINFO table to get its id, which is the revision number. So should be doable easily via JDBC.

              Adam