Running Hibernate 4.3.5, I get an infinite loop here, leading to a StackOverflowError:
org.hibernate.type.EntityType.getIdentifierOrUniqueKeyType(EntityType.java:677)
The method in question is:
public final Type getIdentifierOrUniqueKeyType(Mapping factory) throws MappingException {
if ( isReferenceToPrimaryKey() || uniqueKeyPropertyName == null ) {
return getIdentifierType(factory);
}
else {
Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
if ( type.isEntityType() ) {
type = ( ( EntityType ) type).getIdentifierOrUniqueKeyType( factory );
}
return type;
}
}
Has anyone run into this issue before or know what causes it?
Figured it out, I had created two one-to-one relationships on either end:
<one-to-one name="payment" property-ref="invoice" lazy="proxy" />
<one-to-one name="invoice" property-ref="payment" lazy="proxy" />
Sends Hibernate into an infinite loop. I'll see if there is a bug report on this on Hibernate, because it would not seem impossible to add a check for this and a better error message.
Replacing one end of the relationship with:
<many-to-one name="payment" column="payment_id" unique="true" lazy="proxy" />
Fixed the problem.