<many-to-one name=\"activitySummary\" column=\"bps_acs_id\" class=\"xyz.ActivitySummary\"" />
开发者

How to create two-column unique key constrain with HBM mapping?

开发者 https://www.devze.com 2023-01-30 06:53 出处:网络
I have a hibernate mapping: <properties name=\"lrt_bps_bpr_acs_uk\" unique=\"true\"> <many-to-one name=\"activitySummary\" column=\"bps_acs_id\" class=\"xyz.ActivitySummary\"

I have a hibernate mapping:

<properties name="lrt_bps_bpr_acs_uk" unique="true">
    <many-to-one name="activitySummary" column="bps_acs_id" class="xyz.ActivitySummary"
    unique-key="lrt_bps_bpr_acs_uk"/>
    <many-to-one name="bestPractice" column="bps_bpr_id" class="xyz.BestPractice" 
        unique-key="lrt_bps_bpr_acs_uk"/>
</properties>

I expected that hibernate would开发者_开发百科 create unique constraint on database for this mapping. Nothing like that happened however.

What am I doing wrong?


Seems like you do nothing wrong. We do it the same way in our project and it works fine. I thought to have the same problem once because I couldn't find the constaints in our oracle DB because I thought the specified unique-key attribute value (in your case 'lrt_bps_bpr_acs_uk') is used as constraint_name in the DB. But that isn't the case (at least with oracle DB).


What's the actual DDL that Hibernate is generating? What would be the DDL if you remove the unique-key parameters? What's the Hibernate version?

From the documentation, it seems you are doing it correctly: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-properties


Dont specify name="lrt_bps_bpr_acs_uk" unique="true" in the properties element. It automatically takes it and applies the constraint with unique-key

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号