Hello,
This is my first post in the hibernate forum, so please, bear with me :)
I am trying to implement Hibernate Envers in an application I developed.
I am using Hibernate 5.2.7 and Postgres 9.4.
I have used the @Audited and @NotAudited tags, and follows the documentation, and everything gets saved beautifully on the database, but I cannot retrieve my entities.
Please see my entities:
Code:
@MappedSuperclass
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Audited
public class PersistentObject {
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
private Long id;
Code:
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Entity
@Audited
public abstract class Agent extends PersistentObject implements Comparable<Agent>, Identifiable {
@ManyToMany(mappedBy = "assignedTo")
private List<Agent> assignedAgents = new ArrayList<>();
@ManyToMany
private List<Agent> assignedTo = new ArrayList<>();
...
Code:
@Entity(name = "User")
@Table(name = "SNSUser")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Audited
public class User extends Agent {
@Column(unique = true)
private String username;
private String email;
....
Now, as I modify my users, I can see all the modifications bring written in SNSUser_AUD table.
I can also list revisions, and everything works fine.
However, once I retrieve my entity, and try to access the method
entity.getAssignedAgents(), the following exception is thrown:
Code:
Caused by: org.hibernate.QueryException: could not resolve property: originalId.assignedAgents_id of: Agent_Agent_AUD [select new list(ee__, e__) from Agent_Agent_AUD ee__, de.ccsys.sns.models.Agent_AUD e__ where ee__.originalId.assignedAgents_id = :assignedAgents_id and e__.originalId.REV.id = (select max(e2__.originalId.REV.id) from de.ccsys.sns.models.Agent_AUD e2__ where e2__.originalId.REV.id <= :revision and e__.originalId.id = e2__.originalId.id) and ee__.originalId.REV.id = (select max(ee2__.originalId.REV.id) from Agent_Agent_AUD ee2__ where ee2__.originalId.REV.id <= :revision and ee__.originalId.assignedAgents_id = ee2__.originalId.assignedAgents_id and ee__.originalId.Agent_id = ee2__.originalId.Agent_id) and ee__.REVTYPE != :delrevisiontype and e__.REVTYPE != :delrevisiontype and (ee__.originalId.Agent_id = e__.originalId.id or (ee__.originalId.Agent_id is null and e__.originalId.id is null))]
at org.hibernate.QueryException.generateQueryException(QueryException.java:120)
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:217)
The database was implemented by hibernate schema generator itself (hbm2dll.auto=update).
Here stands the current table:
Code:
CREATE TABLE agent_agent_aud
(
rev integer NOT NULL,
assignedagents_id bigint NOT NULL,
assignedto_id bigint NOT NULL,
revtype smallint,
CONSTRAINT agent_agent_aud_pkey PRIMARY KEY (rev, assignedagents_id, assignedto_id),
CONSTRAINT fkccop2twpfcyjf0jy9n27a0hj2 FOREIGN KEY (rev)
REFERENCES snsrevision (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
Could anyone point me in the right direction here?