use of jakarta.persistence.EmbeddedId in project hibernate-orm by hibernate.
the class AnnotationBinder method processId.
private static void processId(PropertyHolder propertyHolder, PropertyData inferredData, SimpleValue idValue, Map<String, IdentifierGeneratorDefinition> classGenerators, boolean isIdentifierMapper, MetadataBuildingContext buildingContext) {
if (isIdentifierMapper) {
throw new AnnotationException("@IdClass class should not have @Id nor @EmbeddedId properties: " + BinderHelper.getPath(propertyHolder, inferredData));
}
XClass entityXClass = inferredData.getClassOrElement();
XProperty idXProperty = inferredData.getProperty();
final Annotation generatorAnnotation = HCANNHelper.findContainingAnnotation(idXProperty, IdGeneratorType.class);
if (generatorAnnotation != null) {
idValue.setCustomIdGeneratorCreator(new CustomIdGeneratorCreator(generatorAnnotation, idXProperty));
} else {
// manage composite related metadata
// guess if its a component and find id data access (property, field etc)
final boolean isComponent = entityXClass.isAnnotationPresent(Embeddable.class) || idXProperty.isAnnotationPresent(EmbeddedId.class);
GeneratedValue generatedValue = idXProperty.getAnnotation(GeneratedValue.class);
String generatorType = generatedValue != null ? generatorType(generatedValue, buildingContext, entityXClass) : "assigned";
String generatorName = generatedValue != null ? generatedValue.generator() : "";
if (isComponent) {
// a component must not have any generator
generatorType = "assigned";
}
if (isGlobalGeneratorNameGlobal(buildingContext)) {
buildGenerators(idXProperty, buildingContext);
SecondPass secondPass = new IdGeneratorResolverSecondPass(idValue, idXProperty, generatorType, generatorName, buildingContext);
buildingContext.getMetadataCollector().addSecondPass(secondPass);
} else {
// clone classGenerator and override with local values
HashMap<String, IdentifierGeneratorDefinition> localGenerators = new HashMap<>(classGenerators);
localGenerators.putAll(buildGenerators(idXProperty, buildingContext));
makeIdGenerator(idValue, idXProperty, generatorType, generatorName, buildingContext, localGenerators);
}
if (LOG.isTraceEnabled()) {
LOG.tracev("Bind {0} on {1}", (isComponent ? "@EmbeddedId" : "@Id"), inferredData.getPropertyName());
}
}
}
Aggregations