0

I have three Tables A, B, and AB. AB table is a relationship table. So AB_AUD table has abID as PK, and aId, bID, Revision Info. I've got list of 'bIds' and would like to retrieve audit data from AB_AUD table using the list. My code block is

AuditQuery query = auditReader.createQuery()
    .forRevisionsOfEntity(AB.class, false, true)
    .add(AuditEntity.property("bId").in(bIds))
    .addOrder(AuditEntity.revisionNumber().desc());

This throws exception :could not resolve property of bId. Even I tried equating with single bId to retrieve audit data for a single bId which threw same exception. I would like to know if there is any mistake in the code. For now I am doing a for loop to retrieve data like this:

for (B b : listofB's)
{
    AuditQuery query = auditReader.createQuery()
        .forRevisionsOfEntity(AB.class, false, true)
        .add(AuditEntity.property("b").eq(b))
        .addOrder(AuditEntity.revisionNumber().desc());
}

Which runs sql query for every B, which isn't a good way.

Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
shashdr
  • 83
  • 2
  • 8

1 Answers1

0

If your property name is b then why are you using bId in the query. Update the query to use b as below:

            .forRevisionsOfEntity(AB.class, false, true)
             .add(AuditEntity.property("b").in(istofB's))
             .addOrder(AuditEntity.revisionNumber().desc());

This should work.

Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • AuditEntity.property("b").in(istofB's) didn't work ,I feel comparing property b to a list of objects is causing error. Generating sql query based on bId should also retrieve audit data as bId is the column in AB table.Please advise. – shashdr Oct 09 '12 at 16:19
  • Desn't sound right. Did you still get error saying property `b` undefined? – Yogendra Singh Oct 09 '12 at 17:06