Hibernate's "Table" annotations does not cooperate well with custom quoting
naming strategy
-------------------------------------------------------------------------------------------
Key: HHH-6328
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-6328
Project: Hibernate Core
Issue Type: Bug
Components: annotations
Affects Versions: 3.6.5
Reporter: Richard Eckart de Castilho
I have implemented a custom QuotingNamingStrategy that quotes table names, so that they
are properly treated as case sensitive and to avoid issues with reserved names.
I also have auxiliary "Table" annotations to have Hibernate create indexes on my
behalf. Of course the table name is not quoted in these annotations:
{code}
@org.hibernate.annotations.Table(appliesTo="MyTable",indexes = {
@Index(name="column1", columnNames="column2")})
{code}
Now I get the exception:
{noformat}
org.hibernate.AnnotationException: @org.hibernate.annotations.Table references an unknown
table: MyTable
at
org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:877)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
{noformat}
Debugging the issue, I find that the EntityBinder tries to match the quoted name against
the "appliesTo" attribute of the Table annotation, but the value of this
attribute is not processed by my custom QuotingNamingStrategy. Thus, the table cannot be
found:
{code}
public void processComplementaryTableDefinitions(org.hibernate.annotations.Table table) {
//comment and index are processed here
if ( table == null ) return;
String appliedTable = table.appliesTo();
Iterator tables = persistentClass.getTableClosureIterator();
Table hibTable = null;
while ( tables.hasNext() ) {
Table pcTable = (Table) tables.next();
// -=> Here the quoted name is compared to the unquoted name from
"appliedTable"
if ( pcTable.getQuotedName().equals( appliedTable ) ) {
//we are in the correct table to find columns
hibTable = pcTable;
break;
}
hibTable = null;
}
if ( hibTable == null ) {
//maybe a join/secondary table
for ( Join join : secondaryTables.values() ) {
if ( join.getTable().getQuotedName().equals( appliedTable ) ) {
hibTable = join.getTable();
break;
}
}
}
if ( hibTable == null ) {
throw new AnnotationException(
"(a)org.hibernate.annotations.Table references an unknown table: " +
appliedTable
);
}
if ( !BinderHelper.isEmptyAnnotationValue( table.comment() ) ) hibTable.setComment(
table.comment() );
TableBinder.addIndexes( hibTable, table.indexes(), mappings );
}
{code}
I do believe that the value of the "appliedTo" attribute should be passed
through the naming strategy before comparing against the table name.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira