On Java Development

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

Sorting Records Using JPA Annotations

without comments


This post shows how to use JPA Annotations to sort the detail records of a @OneToMany relationship. The details about how to define a @OneToMany relationship can be read in the post titled Describing a Header/Detail Relationship Using JPA Annotations With Hibernate. This post expands on the annotations defined for the files PHSPRRQHD and PHSPRRQDT.

The Problem
This screen shot shows data displayed in the data table that is in descending sequence by date. This is due to the fact the data is in arrival sequence. The data needs to be in ascending sequence by date.

The Remedy
To sort the detail in ascending sequence by date, JPA annotations are used. Shown below are the JPA annotations in the entity class for the Premium Request Header file (PHSPRRQHD). As described in the original post, lines 1 and 2 defines a one-to-many relationship between the header file and the associated detail file (PHSPRRQDT) and to join the header and detail using the header’s PRHREQID field and the detail’s PRDREQID field.

Line 3 was added to indicate that for the premiumRequestDetail object, which is a collection of records from the detail file, sort the records in ascending sequence using the PRDDATEINC .

Now, when the data is displayed into the data grid, it is arranged in the proper sequence as shown.
Problem solved.

Written by admin

February 7th, 2014 at 10:25 am

Leave a Reply

You must be logged in to post a comment.