It looks like I hit a bug either in java.persistence javadoc or in Hibernate implementation.
The definition of table field for @Column says:
Quote:
The name of the table that contains the column. If absent the column is assumed to be in the primary table.
It is not stated that it
should not be the primary table. However, if you don't have any secondary table and put the primary table in the field, Hibernate raises exception:
Code:
org.hibernate.AnnotationException: Cannot find the expected secondary table: no <table-name> available for <entity-name>
at org.hibernate.cfg.Ejb3Column.getJoin(Ejb3Column.java:293)
at org.hibernate.cfg.Ejb3Column.getTable(Ejb3Column.java:272)
at org.hibernate.cfg.annotations.SimpleValueBinder.make(SimpleValueBinder.java:222)
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1905)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1281)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:534)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1225)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:159)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
I think if this field is supposed to hold only the secondary table, it should be stated explicitly in the javadoc.
Am I wrong?
Thanks,
Yevgeny