Hibernate Enver : @AuditMappedBy is not working

691 views Asked by At

I created an instance of A, defined name, with a blank collection of entities B and save it into DB. This is revision #1. Now I use the following statement to get all initial revision of class A

//Get revisions
A a  = auditReader.find(A.class, aId, revisions.get(0));

I am getting an exception

could not resolve property: aId_id of: .B_AUDIT [select e__ from B_AUDIT e__ where e__.aId_id = :a_id and e__.originalId.REV.id <= :revision and REVTYPE != :delrevisiontype and (e__.REVEND.id > :revision or e__.REVEND is null)]

Following are my class details

@Table(name = "A")
@Audited
public class A{
@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    ....

    @OneToMany(mappedBy = "aId")
    @AuditMappedBy(mappedBy = "aId")
    private List<B> b;
}

which has @oneToMany relationship with B

@Entity
@Table(name = "B")
@Audited
public class B{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;

    private int aId;
    ...
}

Hibernate Enver Version : 5.1.4.Final

Thank you for your support.

1

There are 1 answers

0
Naros On

If I had to wager a guess, I believe it is likely because of how you decided to map the oppsite side of the @OneToMany relationship inside entity B. You mapped it directly to the primary key value rather than to the entity type itself.

In other words, Envers likely expected this mapping instead:

@Entity 
@Table(name = "B") 
@Audited
public class B {
  // other stuff removed for breavity
  @ManyToOne
  private A a;
}