---
title: "Incorrect SQL generated when one-to-many foreign key is in a discriminated subcl"
author: "maflyp"
date: "2012-03-05T14:05:59Z"
tags: []
categories: ["数据库"]
slug: "incorrect-sql-generated-when-one-to-many-foreign-key-is-in-a-discriminated-subcl"
draft: false
lastmod: "2011-12-05T23:15:06Z"
id: 1292659
url: "https://maflyp.iteye.com/blog/1292659"
---

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会去访问父类中并不存在的某个列。 一个解决此问题的方法是使用，而不是。可以参考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 is used for one to one mapping.