HHH-14280 - audit query does not work when @IdClass composite identifier contains association to a not audited entity

Add possible solution
This commit is contained in:
Rapenok, Ivan 2020-10-25 18:28:08 +03:00 committed by Chris Cranford
parent 0ea49974d0
commit f4994a4cf6
1 changed files with 13 additions and 3 deletions

View File

@ -13,6 +13,8 @@ import java.util.Map;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.envers.boot.internal.EnversService; import org.hibernate.envers.boot.internal.EnversService;
import org.hibernate.envers.internal.entities.EntitiesConfigurations;
import org.hibernate.envers.internal.entities.EntityConfiguration;
import org.hibernate.envers.internal.entities.PropertyData; import org.hibernate.envers.internal.entities.PropertyData;
import org.hibernate.envers.internal.tools.ReflectionTools; import org.hibernate.envers.internal.tools.ReflectionTools;
import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.Getter;
@ -25,7 +27,7 @@ import org.hibernate.type.EntityType;
* An extension to the {@link SingleIdMapper} implementation that supports the use case of an {@code @IdClass} * An extension to the {@link SingleIdMapper} implementation that supports the use case of an {@code @IdClass}
* mapping that contains an entity association where the {@code @IdClass} stores the primary key of the * mapping that contains an entity association where the {@code @IdClass} stores the primary key of the
* associated entity rather than the entity object itself. * associated entity rather than the entity object itself.
* * <p>
* Internally this mapper is capable of transforming the primary key values into the associated entity object * Internally this mapper is capable of transforming the primary key values into the associated entity object
* and vice versa depending upon the operation. * and vice versa depending upon the operation.
* *
@ -203,8 +205,16 @@ public class VirtualEntitySingleIdMapper extends SingleIdMapper {
} }
private static IdMapper resolveEntityIdMapper(ServiceRegistry serviceRegistry, String entityName) { private static IdMapper resolveEntityIdMapper(ServiceRegistry serviceRegistry, String entityName) {
final EnversService enversService = serviceRegistry.getService( EnversService.class ); final EntitiesConfigurations entitiesConfigurations = serviceRegistry.getService( EnversService.class )
return enversService.getEntitiesConfigurations().get( entityName ).getIdMapper(); .getEntitiesConfigurations();
final EntityConfiguration auditedEntityConfiguration = entitiesConfigurations.get( entityName );
if ( auditedEntityConfiguration != null ) {
return auditedEntityConfiguration.getIdMapper();
}
else {
return entitiesConfigurations.getNotVersionEntityConfiguration( entityName ).getIdMapper();
}
} }
} }