Incorrect SQL generated when one-to-many foreign key is in a discriminated subcl

A bug reported for hibernate:http://opensource.atlassian.com/projects/hibernate/browse/HHH-1015;http://opensource.atlassian.com/projects/hibernate/browse/HHH-2898



可以看到,Hibernate不能认识到用于外键连接的列是子类对应表中的某个列。或者说,会认为子类中的这个列也必然是父类对应表中的列。所导致的问题就是,Hibernate会去访问父类中并不存在的某个列。

一个解决此问题的方法是使用<joined-subclass>,而不是<subclass name="EventPayer" discriminator-value="-3"><join table="event_payer">。可以参考HHH-2898.



PS:Both of joined-subclass and subclass can be used for 'table per subclass'.

PS2: joined-subclass和subclass没有办法同时使用. Can't mix subclass and joined-subclass strategies for a hierarchy. You can try to use one-to-one mapping to substitute the joined-subclass.

PS3: PK must be used for the mapping of root class and subclass in  'table per subclass'.scenario. It means <joined-subclass> is used for one to one mapping.


猜你喜欢

转载自maflyp.iteye.com/blog/1292659
今日推荐