Hibernate version:
3.1 mainline
I have been porting an application from Hibernate 2.1.[latest] to Hibernate 3.1 (working off of mainline right now).
I noticed that foreign keys are now generated by default on all collections, regardless of the value of the inverse attribute. In Hibernate 2.1, inverse="true" would prevent a foreign key from being generated (which made sense).
Now it appears the only way to override this is to add a foreign-key="none" attribute on the key element.
This is caused by an if block being removed (note the // comments) in org.hibernate.mapping.Collection:
Code:
private void createForeignKeys() throws MappingException {
// if ( !isInverse() ) { // for inverse collections, let the "other end" handle it
if ( referencedPropertyName == null ) {
getElement().createForeignKey();
key.createForeignKeyOfEntity( getOwner().getEntityName() );
}
// }
}
I trolled through the CVS logs in org.hibernate.mapping.Collection and found the checkin where this was commented out:
http://cvs.sourceforge.net/viewcvs.py/h ... 1.3&r2=1.4
http://cvs.sourceforge.net/viewcvs.py/h ... iew=markup
I looked at the bugs referenced in the checkin, and didn't see any reason in the bugs why this would have been disabled (although I don't have access to the TODO-50 bug).
I was going to add a note to the Hibernate 3 migration wiki page, but I figured I'd check in here first.
Thanks ~
Peter