• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beginner needs help with @OneToMany relationship (jpa)

 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a "Statement" class that holds a collection of "Amount" classes as follows:

This is part of the Statement class:


The Amount class has a pk made up of several fields as follows:



I want, when I retrieve my collection of Amount intances, that they be sorted by internalReference.

Do you see my point? Is there a way to specify that?

Thanks in advance,

Julien.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What issue are you having exactly? You can use an @OrderBy on the OneToMany mapping to have the database result ordered.

Is your IdClass an embedded id? If it is then you may need to duplicate the mapping for the internalReference in an attribute in your Amount class to allow ordering on it (make it insertable/updatable=false as it is a read-only mapping). Or don't use an embedded Id.

You could also instead sort the collection in your get method, or in your application/UI.

Depending on what JPA provider you are using, your provider may have additional ordering options.
 
Darvesh Niz
Ranch Hand
Posts: 121
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic