On Java Development

All things related to Java development, from the perspective of a caveman.

Using Hibernate to Update a Record with a Composite Key

without comments


This post shows how to use Hibernate to update a single record using a composite key. This approach differs a bit when using a file defined with a identity field, which is a little easier to update code-wise.

The Service Class
Starting on line 126, the update method manages the high-level processing which entails starting the commitment control transaction, calling the DAO’s update method and when control returns, committing the update.

The Composite Key Class
This class contains the key fields for the file.

The Entity Class
This class contains the definitions for the composite key class and the rest of the record’s fields.

The DAO Class
The Data Access Object class performs the low-level processing responsible for performing CRUD operations against the file. The update method begins at line 130.

This post presented the classes involved with updating a file using Hibernate. Composite keys are needed when the file was designed without an identity field.

Written by admin

June 5th, 2014 at 5:00 am

Posted in Hibernate

Leave a Reply

You must be logged in to post a comment.