[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-6825) AuditException with @OneToOne-mappedBy and @PrimaryKeyJoinColumn
Lukasz Antoniak (JIRA)
noreply at atlassian.com
Wed Jan 18 15:28:14 EST 2012
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-6825?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Lukasz Antoniak resolved HHH-6825.
----------------------------------
Resolution: Fixed
Fix Version/s: 4.1.0
Assignee: Lukasz Antoniak
> AuditException with @OneToOne-mappedBy and @PrimaryKeyJoinColumn
> ----------------------------------------------------------------
>
> Key: HHH-6825
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6825
> Project: Hibernate ORM
> Issue Type: Bug
> Components: envers
> Affects Versions: 4.0.0.CR5
> Environment: JBoss AS 7.1.0 / JDK 1.6.0_29 / Windows 7 64
> Reporter: André Pankraz
> Assignee: Lukasz Antoniak
> Fix For: 4.1.0
>
>
> Both entities are audited:
> Person {
> @OneToOne(mappedBy = "person")
> private Nutzerkonto nutzerkonto;
> }
> Nutzerkonto {
> @OneToOne(optional = false)
> @PrimaryKeyJoinColumn
> private Person person;
> }
> Generate Person-audit:
> reader.createQuery().forRevisionsOfEntity(Person.class, false, true)
> .add(AuditEntity.id().eq(id)) ... .getResultList();
> Caused by: org.hibernate.envers.exception.AuditException: This criterion can only be used on a property that is a relation to another property.
> at org.hibernate.envers.query.criteria.RelatedAuditExpression.addToQuery(RelatedAuditExpression.java:52) [hibernate-envers-4.0.0.CR5.jar:4.0.0.CR5]
> at org.hibernate.envers.query.impl.EntitiesAtRevisionQuery.list(EntitiesAtRevisionQuery.java:94) [hibernate-envers-4.0.0.CR5.jar:4.0.0.CR5]
> at org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:106) [hibernate-envers-4.0.0.CR5.jar:4.0.0.CR5]
> at org.hibernate.envers.entities.mapper.relation.OneToOneNotOwningMapper.mapToEntityFromMap(OneToOneNotOwningMapper.java:80) [hibernate-envers-4.0.0.CR5.jar:4.0.0.CR5]
> at org.hibernate.envers.entities.mapper.MultiPropertyMapper.mapToEntityFromMap(MultiPropertyMapper.java:115) [hibernate-envers-4.0.0.CR5.jar:4.0.0.CR5]
> at org.hibernate.envers.entities.EntityInstantiator.createInstanceFromVersionsEntity(EntityInstantiator.java:99) [hibernate-envers-4.0.0.CR5.jar:4.0.0.CR5]
> at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:134) [hibernate-envers-4.0.0.CR5.jar:4.0.0.CR5]
> at org.hibernate.envers.query.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:102) [hibernate-envers-4.0.0.CR5.jar:4.0.0.CR5]
> Exception via:
> org.hibernate.envers.query.criteria.RelatedAuditExpression:
> public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
> String propertyName = propertyNameGetter.get(auditCfg);
>
> RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(auditCfg, entityName, propertyName);
> if (relatedEntity == null) {
> throw new AuditException("This criterion can only be used on a property that is " +
> "a relation to another property.");
> } else {
> relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, null, equals);
> }
> }
> propertyName is null!
> triggered via org.hibernate.envers.entities.mapper.relation.OneToOneNotOwningMapper.mapToEntityFromMap:
> value = versionsReader.createQuery().forEntitiesAtRevision(entityClass, owningEntityName, revision)
> .add(AuditEntity.relatedId(owningReferencePropertyName).eq(primaryKey)).getSingleResult();
> OneToOneNotOwningMapper.owningReferencePropertyName is null => this is the major problem here I think and may be connected with @PrimaryKeyJoinColumn. Mapper must choose the primary key and not the join column then.
> quick hack:
> public OneToOneNotOwningMapper(String owningReferencePropertyName, String owningEntityName,
> PropertyData propertyData) {
> // HACK for @OneToOne with @PrimaryKeyJoinColumn => null
> this.owningReferencePropertyName = owningReferencePropertyName == null ? "id" : owningReferencePropertyName;
> should handle this in org.hibernate.envers.configuration.metadata.ToOneRelationMetadataGenerator.addOneToOneNotOwning?! but better the experts... ;)
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list