On Java Development

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

Using Partial Keys with Hibernate HQL

without comments

Introduction

This post shows how to use a partial key when the key fields are isolated as a composite key under Hibernate.

Shown below is a method belonging to a DAO for the policy master. It accepts a single argument for policy number. The method uses the composite key that is comprised of the primary key fields which are company, block and policy.

Line 6 sets the policy field of the composite key object with the policy value passed, leaving the other 2 fields for company and block uninitialized, or blanks. The HQL statement is built as normal and references the single field for policy contained in pspmpolpk01 as seen on line 10.

Execution results in a list of policies having the policy number passed to the HQL. Company and block are automatically filled in.

Written by admin

April 10th, 2014 at 8:55 am

Posted in Hibernate

Leave a Reply

You must be logged in to post a comment.