I was wondering about the justification for a certain limitation/restriction in Hibernate tools. In the hibernate.reveng.xml file, the documentation states that in the <foreign-key> the constraint-name is required. Firstly, why does the dtd not reflect this requirement? Secondly, why is this a required element in the first place? The OverrideBinder.bindForeignKeys method calls Table.createForeignKey, which will generate a unique(?) FK name if the constraintName is not specified. Subsequent to this call, prior to processing the directives embedded in the <foreign-key> element, it checks to see if the constraint-name was specified before processing the embedded directives. So, basically, if you do not specify the constraint-name, it generates the FK anyways and then promptly ignores the embedded directives (e.g. <set exclude="true"/>).
I came across this problem in my reverse engineering when adding foreign keys in the hibernate.reveng.xml file, where I did not realize that the constraint-name was required and was baffled as to why it was ignoring my foreign-key directives. Unfortunately, the DBAs left out a bunch of foreign keys for some unknown reason, and I have 400 tables to map, adding about 1000 foreign keys. Most of these FKs are not mapped bidirectionally, so I wanted them to ignore the <set> side of things in most circumstances. But I really do not want to have to put in 1000 made up, do-nothing foreign key constraint names (FK0001, FK0002, FK0003, etc., ad infinitum, ad nauseum) when Table.createForeignKey will do it for me.
Simple fix/enhancement: Change documentation to state that if the constraint-name is not specified, a generated constraint-name will be supplied. Remove/enhance the StringHelper.isNotEmpty(constraintName) check in the OverrideBinder.bindForeignKeys method.
|