[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6317?page=c...
]
Lukasz Antoniak commented on HHH-6317:
--------------------------------------
The issue here is that the owning side of one-to-one relation is not being audited. If
{{AnEntity}} was the owning side (omit setting {{mappedBy}} to {{"anEntity"}} on
the {{target}} attribute) everything would work fine. To summarize, does the following
mapping cause your problem (see below)?
{code:title=AnEntity|borderStyle=solid}
@Entity
@Audited
public class AnEntity {
@Id
@GeneratedValue
private Long id;
@OneToOne(optional=false, mappedBy="anEntity")
@Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
private TargetEntity target;
}
{code}
{code:title=TargetEntity|borderStyle=solid}
@Entity
public class TargetEntity {
@Id
@GeneratedValue
private Long id;
@OneToOne
// I don't know why you've used @ManyToOne annotation here.
private AnEntity anEntity;
}
{code}
In my opinion we should load a proxy object of current (non-historical) version of
{{TargetEntity}} (see {{Audited.targetAuditMode}} JavaDoc) to {{AnEntity.target}}
property.
Regards,
Lukasz Antoniak
Retrieving
-----------
Key: HHH-6317
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6317
Project: Hibernate Core
Issue Type: Bug
Components: envers
Affects Versions: 3.6.5
Reporter: Clint Popetz
For the following mapping:
{code}
public class AnEntity extends HibernatePersistedObject {
@Id
@GeneratedValue
private Long id;
@OneToOne(optional=false,mappedBy="anEntity")
private TargetEntity target;
}
public class TargetEntity {
@Id
@GeneratedValue
private Long id;
@ManyToOne
private AnEntity anEntity;
}
{code}
and the following query:
{code}
AuditReaderFactory.get(em).createQuery().
forRevisionsOfEntity(AnEntity.class,false,false).
add(AuditEntity.id().eq(id)).addOrder(AuditEntity.revisionNumber().desc()).
setMaxResults(1).getSingleResult()
{code}
I get an NPE because the there is no EntityConfiguration for TargetEntity, as it is not
audited:
{noformat}
java.lang.NullPointerException
at
org.hibernate.envers.query.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:81)
at
org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108)
at
org.hibernate.envers.entities.mapper.relation.OneToOneNotOwningMapper.mapToEntityFromMap(OneToOneNotOwningMapper.java:82)
at
org.hibernate.envers.entities.mapper.MultiPropertyMapper.mapToEntityFromMap(MultiPropertyMapper.java:118)
at
org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:100)
at
org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:135)
at
org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:108)
{noformat}
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira