Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8892745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:05:05+00:00 2026-06-14T23:05:05+00:00

I am having a huge problem trying to get Envers to execute the query

  • 0

I am having a huge problem trying to get Envers to execute the query I need. If anyone can let me know if this is possible from within Envers or if I need to excute the SQL directly that would be a tremendous help!

Here is the problem. I have a made-up “Project” entity – any Entity class will do – that is audited. I am trying to get the latest revision of EVERY Project entity via an AuditReader query.

When I do this (the other parts of the code shouldn’t matter):

AggregatedAuditExpression maxExpression = AuditEntity.revisionNumber().maximize();
maxExpression.add(AuditEntity.id().eq("12345"));
query.add(maxExpression);

and turn on the SQL output, I see this query being generated:

Hibernate: select project_a0_.id as id6_0_, project_a0_.REV as REV6_0_, auditrevis1_.id as id0_1_,
project_a0_.REVTYPE as REVTYPE6_0_, project_a0_.description as descript4_6_0_, 
auditrevis1_.timestamp     as timestamp0_1_, auditrevis1_.username as username0_1_ 
from MYSCHEMA.project_AUD project_a0_ cross join MYSCHEMA.REVINFO auditrevis1_ 
where project_a0_.REV=

(select max(project_a2_.REV) from MYSCHEMA.project_AUD project_a2_ 
               where project_a2_.id=?) 

and project_a0_.REV=auditrevis1_.id order by project_a0_.REV asc

Note the “select max” part. It is almost exactly what I need. Just the where clause is wrong I need it to say:
where project_a2_.id=project_a0_.id

I edited it by hand, ran it and it works perfectly. Now it SEEMS like the “addIdsEqualToQuery” method in the IdMapper class lets me do what I want. So if I change out the AuditEntity.id().eq(“12345”) with this:

maxExpression.add(new IdentifierIdsEqAuditExpression());

where IdentifierIdsEqAuditExpression equals:

    class IdentifierIdsEqAuditExpression implements AuditCriterion {    
        @Override
        public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
            auditCfg.getEntCfg().get(entityName).getIdMapper()
                    .addIdsEqualToQuery(parameters, null, auditCfg.getAuditEntCfg().getOriginalIdPropName());
        }    
    }

it should be close – it is. I get:

Invalid path: ‘originalId.id’ [select e__, r from com.mycompany.Project_AUD e_, com.mycompany.audit.AuditRevisionEntity r where id = originalId.id and e_.originalId.REV.id = (select max(_e0.originalId.REV.id) from com.mycompany.Project_AUD e0 where id = originalId.id) and e_.originalId.REV.id = r.id order by e__.originalId.REV.id asc]

The problem is I can’t get it to generate what I need and even if the prefix was changed from “originalId” to the correct one, why does envers start putting that all over the place, rather than in the single location?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:05:06+00:00Added an answer on June 14, 2026 at 11:05 pm

    I’m afraid this is not currently possible with Envers. You would need to add something like parentIdEqual() to maxExpression, but there’s no combinator like that.

    Please open a feature request: https://hibernate.onjira.com/secure/Dashboard.jspa

    As for the originalId, Envers entities have a composite id of the revision number and the original id (which is kept in the originalId sub-property).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a huge problem with the NSTimer object. I can't explain myself this
I've been having a huge problem with this. Xcode just simply turned my landscape
I am having a huge problem with this. I want to take my whole
I am having a huge problem with the eventlog on my server. Right let
Im having problem trying to join 3 tables, every time I run the query
I'm having a huge problem trying to figure out a json response from a
I'm trying to create this sliding effect but the only problem I'm having is
I am having a huge problem in all browsers. I have a site where
I've been having a huge headache trying to figure out why the facebook comments
I'm having difficulties when trying to save huge images with C# (I'm talking about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.