How to update a table with composite key using hibernate?
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);
精彩评论