throw new AnnotationException(
"Unable to define/override @Id(s) on a subclass: "
+ propertyHolder.getEntityName()
);
}
RootClass rootClass = ( RootClass ) persistentClass;
String persistentClassName = rootClass.getClassName();
SimpleValue id;
final String propertyName = inferredData.getPropertyName();
HashMap<String, IdGenerator> localGenerators = new HashMap<String, IdGenerator>();
if ( isComposite ) {
id = fillComponent(
propertyHolder, inferredData, baseInferredData, propertyAccessor,
false, entityBinder, isEmbedded, isIdentifierMapper, false, mappings, inheritanceStatePerClass
);
Component componentId = ( Component ) id;
componentId.setKey( true );
if ( rootClass.getIdentifier() != null ) {
throw new AnnotationException( componentId.getComponentClassName() + " must not have @Id properties when used as an @EmbeddedId" );
}
if ( componentId.getPropertySpan() == 0 ) {
throw new AnnotationException( componentId.getComponentClassName() + " has no persistent id property" );
}
//tuplizers
XProperty property = inferredData.getProperty();
setupComponentTuplizer( property, componentId );
}
else {
//TODO I think this branch is never used. Remove.
for ( Ejb3Column column : columns ) {
column.forceNotNull(); //this is an id
}
SimpleValueBinder value = new SimpleValueBinder();
value.setPropertyName( propertyName );
value.setReturnedClassName( inferredData.getTypeName() );
value.setColumns( columns );
value.setPersistentClassName( persistentClassName );
value.setMappings( mappings );
value.setType( inferredData.getProperty(), inferredData.getClassOrElement() );
id = value.make();
}
rootClass.setIdentifier( id );
BinderHelper.makeIdGenerator( id, generatorType, generatorName, mappings, localGenerators );
if ( isEmbedded ) {
rootClass.setEmbeddedIdentifier( inferredData.getPropertyClass() == null );
}
else {
PropertyBinder binder = new PropertyBinder();
binder.setName( propertyName );
binder.setValue( id );
binder.setAccessType( inferredData.getDefaultAccess() );
binder.setProperty( inferredData.getProperty() );
Property prop = binder.makeProperty();
rootClass.setIdentifierProperty( prop );
//if the id property is on a superclass, update the metamodel
final org.hibernate.mapping.MappedSuperclass superclass = BinderHelper.getMappedSuperclassOrNull(
inferredData.getDeclaringClass(),
inheritanceStatePerClass,
mappings
);
if ( superclass != null ) {
superclass.setDeclaredIdentifierProperty( prop );
}
else {
//we know the property is on the actual entity
rootClass.setDeclaredIdentifierProperty( prop );
}
}
}