开发者

How to update a table with composite key using hibernate?

开发者 https://www.devze.com 2022-12-23 07:25 出处:网络
I am newbie to hibernate. If there is a table which has a composite key, h开发者_开发技巧ow to update the table using hibernate.You should be able to use a composite-id for that.

I am newbie to hibernate. If there is a table which has a composite key, h开发者_开发技巧ow to update the table using hibernate.


You should be able to use a composite-id for that.

Example copied from the link:

<composite-id
    name="propertyName"
    class="ClassName"
    mapped="true|false"
    access="field|property|ClassName">
    node="element-name|."

    <key-property name="propertyName" type="typename" column="column_name"/>
    <key-many-to-one name="propertyName" class="ClassName" column="column_name"/>
    ......
</composite-id>

You can then retrieve the record using load instead of get

Book bk1 = new Book();
bk1.setBookId(1);
bk1.setBookName("Hibernate Examples");
bk1.setAuthor("ISHTEK");
Book bk2 = (Book) session.load(Book.class, bk1);

which you can then update after changing your values

session.update(bk1);
0

精彩评论

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

关注公众号