I need some help on Hibernate Envers. I have the following scenario:
I have a Entity in Hibernate/JPA and this Entity has a normal configuration:
package com.algar.fsw.siscos.model;
/**
* TbUsuario generated by hbm2java
*/
@Entity
@Table(name = "SCCTB023_USUARIO")
@Audited
@AuditTable("SCCTB047_USUARIO_ADTRA")
public class Usuario implements java.io.Serializable {
@Id
@Column(name = "NU_USUARIO", nullable = false, scale = 0)
@NotNull
private Long id;
@Column(name = "NO_USUARIO", nullable = false, length = 50)
@NotNull
@Length(max = 50)
private String nome;
@Column(name = "NO_LOGIN", unique = true, nullable = false, length = 16)
@NotNull
@Length(max = 16)
private String login;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "NU_PERFIL", nullable = false)
private Perfil perfil = new Perfil();
@OneToMany(fetch = FetchType.LAZY, mappedBy = "usuario" , cascade = CascadeType.ALL)
private List<UsuarioGrupo> usuariosGrupos = new ArrayList<UsuarioGrupo>();
public Usuario() {
}
public Usuario(Long id ) {
this.id = id;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public Perfil getPerfil() {
return perfil;
}
public void setPerfil(Perfil perfil) {
this.perfil = perfil;
}
public List<UsuarioGrupo> getUsuariosGrupos() {
return usuariosGrupos;
}
public void setUsuariosGrupos(List<UsuarioGrupo> usuariosGrupos) {
this.usuariosGrupos = usuariosGrupos;
}
}
And, this Entity has a relation with this Entity:
package com.algar.fsw.siscos.model;
@Entity
@Table(name = "SCCTB018_PERFIL")
@Audited
@AuditTable("SCCTB042_PERFIL_ADTRA")
public class Perfil implements java.io.Serializable {
@Id
@Column(name = "NU_PERFIL", nullable = false, scale = 0)
@NotNull
private Long id;
@Column(name = "NO_PERFIL", nullable = false, length = 30)
@NotNull
@Enumerated(EnumType.STRING)
private PerfilEnum perfilEnum;
@Column(name = "IC_ATIVO", nullable = false, precision = 1, scale = 0)
private boolean ativo = true;
@Column(name = "NU_NIVEL", nullable = false, precision = 1, scale = 0)
private Long nivel;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return perfilEnum.toString();
}
public boolean isAtivo() {
return ativo;
}
public void setAtivo(boolean ativo) {
this.ativo = ativo;
}
public Long getNivel() {
return nivel;
}
public void setNivel(Long nivel) {
this.nivel = nivel;
}
public PerfilEnum getPerfilEnum() {
return perfilEnum;
}
public void setPerfilEnum(PerfilEnum perfilEnum) {
this.perfilEnum = perfilEnum;
}
}
When I retrieve the Usuario information, everything is ok, but when I call the method getPerfil I receive a NoEntityFoundException because of the ID of the relation. The data exists only in the regular table, in the audited table the data does not exist because the Audited tables were created after the data already exists in the original table so no records were putted on audited table . I need to recover only the ID, I don't need the data from Perfil. So, if I call getPerfil, the only thing I need is the ID information.
Does anyone know a workaround or some solution for this kind of problem?
The reason I need this is because of an WEB application that has a screen that shows the changes in some Entity, showing the values: date_created, property_changed, value_before and value_after. So I'm constructing the logic to compare the revisions manually in java.
Please, could anyone help me?
Thanks