org.hibernate.AnnotationException: @org.hibernate.annotations.Table references an unknown table: MyTable

Hibernate JIRA | Richard Eckart de Castilho | 5 years ago
  1. 0

    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.

    Hibernate JIRA | 5 years ago | Richard Eckart de Castilho
    org.hibernate.AnnotationException: @org.hibernate.annotations.Table references an unknown table: MyTable
  2. 0

    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.

    Hibernate JIRA | 5 years ago | Richard Eckart de Castilho
    org.hibernate.AnnotationException: @org.hibernate.annotations.Table references an unknown table: MyTable
  3. 0

    org.hibernate.AnnotationException: No identifier specified for entity: login.Users

    Stack Overflow | 1 year ago | Rahul
    org.hibernate.AnnotationException: No identifier specified for entity: login.Users at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:265)
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements

    com.br | 1 year ago
    org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: modelo.Analise.metodo
  6. 0

    Hibernate Tutorial Part 4 (c) - How To Create The First Hibernate Application In Eclipse ( Hands On) | How To Make Extra!

    makeonlinecollection.com | 11 months ago
    org.hibernate.AnnotationException: No identifier specified for entity: com.aashi.hibernate.Flight_Info

  1. kjhdofjosvs 1 times, last 1 month ago
  2. Shadd518 1 times, last 4 months ago
  3. MoYapro 2 times, last 5 months ago
5 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.hibernate.AnnotationException

    @org.hibernate.annotations.Table references an unknown table: MyTable

    at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions()
  2. Hibernate
    AnnotationBinder.bindClass
    1. org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:877)
    2. org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
    2 frames