log.debug("Adding audit mapping for property " + referencingEntityName + "." + propertyName +
": one-to-many collection, using a join column on the referenced entity.");
String mappedBy = getMappedBy(propertyValue);
IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
referencedEntityName, propertyAuditingData, false);
IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
// Generating the id mappers data for the referencing side of the relation.
MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping,
mappedBy + "_", referencingEntityName);
// And for the referenced side. The prefixed mapper won't be used (as this collection isn't persisted
// in a join table, so the prefix value is arbitrary).
MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping,
null, referencedEntityName);
// Generating the element mapping.
MiddleComponentData elementComponentData = new MiddleComponentData(
new MiddleRelatedComponentMapper(referencedIdData), 0);
// Generating the index mapping, if an index exists. It can only exists in case a javax.persistence.MapKey
// annotation is present on the entity. So the middleEntityXml will be not be used. The queryGeneratorBuilder
// will only be checked for nullnes.
MiddleComponentData indexComponentData = addIndex(null, null);
// Generating the query generator - it should read directly from the related entity.
RelationQueryGenerator queryGenerator = new OneAuditEntityQueryGenerator(mainGenerator.getGlobalCfg(),
mainGenerator.getVerEntCfg(), referencingIdData, referencedEntityName,
referencedIdMapping.getIdMapper());
// Creating common mapper data.
CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
mainGenerator.getVerEntCfg(), referencedEntityName,
propertyAuditingData.getPropertyData(),
referencingIdData, queryGenerator);
PropertyMapper fakeBidirectionalRelationMapper;
PropertyMapper fakeBidirectionalRelationIndexMapper;
if (fakeOneToManyBidirectional) {
// In case of a fake many-to-one bidirectional relation, we have to generate a mapper which maps
// the mapped-by property name to the id of the related entity (which is the owner of the collection).
String auditMappedBy = propertyAuditingData.getAuditMappedBy();
// Creating a prefixed relation mapper.
IdMapper relMapper = referencingIdMapping.getIdMapper().prefixMappedProperties(
MappingTools.createToOneRelationPrefix(auditMappedBy));
fakeBidirectionalRelationMapper = new ToOneIdMapper(
relMapper,
// The mapper will only be used to map from entity to map, so no need to provide other details