Hibernate 冬眠不';t插入外键

Hibernate 冬眠不';t插入外键,hibernate,orm,foreign-keys,mapping,reverse-engineering,Hibernate,Orm,Foreign Keys,Mapping,Reverse Engineering,我有多对一关系,当我试图插入一个值时,不会传递foreigh键 友好国家 <hibernate-mapping> <class name="servicedb.dal.domain.Country" table="Country" catalog="DB"> <composite-id name="id" class="servicedb.dal.domain.CountryId"> <key-property name="cou

我有多对一关系,当我试图插入一个值时,不会传递foreigh键

友好国家

<hibernate-mapping>
<class name="servicedb.dal.domain.Country" table="Country" catalog="DB">
    <composite-id name="id" class="servicedb.dal.domain.CountryId">
        <key-property name="countryCode" type="string">
            <column name="countryCode" length="2" />
        </key-property>
        <key-property name="localeId" type="int">
            <column name="localeId" />
        </key-property>
    </composite-id>
    <many-to-one name="locale" class="servicedb.dal.domain.Locale" update="false" insert="false" fetch="select">
        <column name="localeId" not-null="true" />
    </many-to-one>
    <property name="name" type="string">
        <column name="name" length="60" not-null="true" />
    </property>
    <set name="cities" table="City" inverse="true" lazy="true" fetch="select">
        <key>
            <column name="countryCode" length="2" not-null="true" />
            <column name="localeId" not-null="true" />
        </key>
        <one-to-many class="servicedb.dal.domain.City" />
    </set>
</class>
但它应该是:

insert into Db.City (name, id, localeId, countryCode) values (?, ?, ?, ?)
并且hibernate抛出以下异常

org.hibernate.exception.GenericJDBCException: Field 'countryCode' doesn't have a default value
我希望提供的信息足以理解错误的原因。如果没有,请具体询问其他信息

我还使用eclipse和reveng.xml对数据库进行反向工程,因此我的hbm文件是自动生成的,我没有使用EJB3注释


编辑:发布了国家和城市实体的完整映射。

多对一城市映射中的
update=“false”insert=“false”
适用于
countryCode
localeId
。由于您的复合id中也映射了
localeId
,因此在生成的查询中会使用它,但对于
countryCode

而言,城市多对一映射中的
update=“false”insert=“false”
适用于
countryCode
localeId
。由于您的复合id中也映射了
localeId
,因此生成的查询中会使用它,但
countryCode

您可以发布整个国家和城市的映射吗?@overmeulen我已经添加了整个国家和城市的映射。请看这里@PSR我已经探讨了这个问题,但如果没有成功,这里的问题似乎就不同了。谢谢,请发布整个国家和城市的地图?@overmeulen我已经添加了整个国家和城市的地图。请看这里@PSR我已经探讨了这个问题,但没有成功,这里的问题似乎不同。谢谢,解决这个问题的办法是什么?我应该创建一个FK(localeId2)来引用国家/地区表吗?是的,我认为这是你最好的选择。那么解决这个问题的方法是什么呢?我应该创建一个FK(localeId2)来引用国家表吗?是的,我认为这是你最好的选择
insert into Db.City (name, id, localeId, countryCode) values (?, ?, ?, ?)
org.hibernate.exception.GenericJDBCException: Field 'countryCode' doesn't have a default value