private void bindSingleIdAnnotation(EntityBinding entityBinding) {
// we know we are dealing w/ a single @Id, but potentially it is defined in a mapped super class
ConfiguredClass configuredClass = entityClass;
EntityClass superEntity = entityClass.getEntityParent();
Hierarchical container = entityBinding.getEntity();
Iterator<SimpleAttribute> iter = null;
while ( configuredClass != null && configuredClass != superEntity ) {
iter = configuredClass.getIdAttributes().iterator();
if ( iter.hasNext() ) {
break;
}
configuredClass = configuredClass.getParent();
container = container.getSuperType();
}
// if we could not find the attribute our assumptions were wrong
if ( iter == null || !iter.hasNext() ) {
throw new AnnotationException(
String.format(
"Unable to find id attribute for class %s",
entityClass.getName()
)
);
}
// now that we have the id attribute we can create the attribute and binding
MappedAttribute idAttribute = iter.next();
Attribute attribute = container.getOrCreateSingularAttribute( idAttribute.getName() );
SimpleAttributeBinding attributeBinding = entityBinding.makeSimpleIdAttributeBinding( attribute );
attributeBinding.initialize( new AttributeBindingStateImpl( (SimpleAttribute) idAttribute ) );
attributeBinding.initialize( new ColumnRelationalStateImpl( (SimpleAttribute) idAttribute, meta ) );
bindSingleIdGeneratedValue( entityBinding, idAttribute.getName() );