原來的問題,從這個問題源於:Hibernate:將引用映射到子表的備選/自然鍵列時出錯?
Why is this JPA 2.0 mapping giving me an error in Eclipse/JBoss Tools?
正如你可以看到這個星座也怪胎Eclipse的大理JPA驗證。 JPA規範似乎讓本作在這裏看到(有點可靠):
Does the JPA specification allow references to non-primary key columns?
張貼在第一個問題的具體代碼也提出了一個Hibernate MappingException:
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: geoareas] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:374)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
at tld.geoareas.Main.main(Main.java:69)
Caused by: org.hibernate.MappingException: property [_tld_geoareas_model_Zip__identifierMapper.country] not found on entity [tld.geoareas.model.Country]
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:378)
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:414)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:115)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1550)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1473)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1389)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362)
... 4 more
Caused by: org.hibernate.MappingException: property [_tld_geoareas_model_Zip__identifierMapper.country] not found on entity [tld.geoareas.model.Country]
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:424)
at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:375)
... 15 more
我特別惱火由「遞歸財產」。畢竟,這只是對GeoAreas子表Countries的UNIQUE,NOT NULL CHAR(2)列的簡單單列引用。請注意,這裏的繼承可能會產生一些影響,但它仍然不是過於複雜的恕我直言。
所以,這是一個Hibernate的bug?