[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-6328) Hibernate's "Table" annotations does not cooperate well with custom quoting naming strategy

Andreas Hackl (JIRA) noreply at atlassian.com
Thu Apr 26 10:25:48 EDT 2012


    [ https://hibernate.onjira.com/browse/HHH-6328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=46432#comment-46432 ] 

Andreas Hackl commented on HHH-6328:
------------------------------------

Will this bug be fixed? It also occurs when using Hibernate 4.1.2.Final.

> Hibernate's "Table" annotations does not cooperate well with custom quoting naming strategy
> -------------------------------------------------------------------------------------------
>
>                 Key: HHH-6328
>                 URL: https://hibernate.onjira.com/browse/HHH-6328
>             Project: Hibernate ORM
>          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(
> 					"@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.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list