I have three classes A, B and C; C is derived from B, both classes are mapped to the same table. A has an audited 1:n relation to C with an additional Where-clause; A is audited, C is not. No when I search for an audited version of A and try to access the C's of A, I get an SQL-syntax exception:
Class A {code : package com title=A . sample;
import java .util.Set; } import javax.annotation.Generated; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToMany; import javax.persistence.Table;
import org.hibernate.annotations.Where; import org.hibernate.envers.AuditJoinTable; import org.hibernate.envers.Audited; import org.hibernate.envers.RelationTargetAuditMode;
@Entity @Audited @Table(name="A_tab") public class A { @Id @GeneratedValue @Column(name="id") Long id; @Column(name="name" ) String name; @OneToMany @JoinColumn(name="allC") @Where(clause = "TYPE = 'C'") @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) @AuditJoinTable(name="A_C_AUD") Set<C> allMyC; public Long getId() { return id; } private void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set<C> getAllMyC() { return allMyC; } public void setAllMyC(Set<C> allC) { this.allMyC = allC; } } {code} {code:title = ============================
Class B : package com . sample; java} import javax.persistence.Column; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorType; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table;
import org.hibernate.envers.Audited;
@Entity @Table(name="B_tab") @Audited @DiscriminatorColumn( name="type", discriminatorType=DiscriminatorType.STRING ) @DiscriminatorValue(value="B") public class B { @Id @GeneratedValue @Column(name="id") Long id; @Column(name="name" ) String name; public Long getId() { return id; } private void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; }
} {code} {code:title = ============================
Class C :
package com . sample; java} import javax.persistence.DiscriminatorValue; import javax.persistence.Entity;
@Entity @DiscriminatorValue(value="C") public class C extends B { } {code }
============================= Searching for rev. 2 of an A with id 2: {code} AuditReader reader = AuditReaderFactory.get(session); A ainst = reader.find(A.class, (long)2, 2); Set<C> allC = ainst.getAllMyC(); // Here the problem occurs System.out.println(allC.isEmpty()); {code} In line three I get an exception: {noformat} WARN: SQL Error: 1054, SQLState: 42S22 05.10.2014 21:35:12 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR: Unknown column 'a_c_aud0_.TYPE' in 'where clause' {noformat} Thats correct, because the table of class B contains a column "TYPE", but the table for auditing the relation does not. The sql is {noformat} "select a_c_aud0_.REV as col_0_0_, a_c_aud0_.allC as col_0_1_, a_c_aud0_.id as col_0_2_, c1_.id as col_1_0_ from A_C_AUD a_c_aud0_ cross join B_tab c1_ where ( a_c_aud0_.TYPE = 'C') and c1_.type='C' and a_c_aud0_.id=c1_.id and a_c_aud0_.allC=? and a_c_aud0_.REV=(select max(a_c_aud2_.REV) from A_C_AUD a_c_aud2_ where ( a_c_aud2_.TYPE = 'C') and a_c_aud2_.REV<=? and a_c_aud0_.allC=a_c_aud2_.allC and a_c_aud0_.id=a_c_aud2_.id) and a_c_aud0_.REVTYPE<>?" {noformat} |
|