I configured auditing through hibernate-envers library and it works fine, until I wanted to read the history through AuditReader API.
This is the code:
AuditReader auditReader = AuditReaderFactory.get(entityManager);
List<Number> revisionNumbers = auditReader.getRevisions(Queue.class, queue.getId());
for (Number rev : revisionNumbers) {
Queue auditedQueue = auditReader.find(Queue.class, queue.getId(), rev);
audQueues.add(auditedQueue);
}
The exception thrown is org.postgresql.util.PSQLException: ERROR: operator does not exist: smallint <> bytea Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. Position: 879
I configured sql logging and I see the failing query:
select queue_aud0_.ID as ID12_, queue_aud0_.REV as REV12_, queue_aud0_.REVTYPE as REVTYPE12_ from CMSMS_QUEUE_AUD queue_aud0_ where (queue_aud0_.REV=(select max(queue_aud1_.REV) from CMSMS_QUEUE_AUD queue_aud1_ where (queue_aud1_.REV<=? )and(queue_aud0_.ID=queue_aud1_.ID )))and(queue_aud0_.REVTYPE<>? )and(queue_aud0_.ID=? )
There are more columns selected but they are not important right now... The parameters used by hibernate are:
bindNamedParameters() TEST_NEW -> _p1 [3]
bindNamedParameters() DEL -> _p0 [2]
bindNamedParameters() 5 -> revision [1]
I tried running the query with these parameters and it throws the same exception. The reason is the second parameter queue_aud0_.REVTYPE<>?, because hibernate is trying to set there 'DEL' string while REVTYPE is smallint. Thats weird, because the tables were auto generated by hibernate... Any idea why does it do this??
I use version 4.2.0.Final
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-envers</artifactId>
<version>4.2.0.Final</version>
</dependency>
After playing a bit with dependencies, it works now. I switched Hibernate to 5.3.0.Final and SpringFramework to 5.0.5.RELEASE. Also had remove some JPA dependency that was redundant. Cannot say exactly, what solved the problem, since I had to change these all dependencies together to even run the application.