-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: hibernate how to order by join table field
PostPosted: Sun Sep 25, 2016 11:54 am 
Newbie

Joined: Tue Sep 20, 2016 11:54 am
Posts: 3
I have two tables `chapter` and `chapter_title_1`, there is a fk `chapter_id` in table `chapter_title_1` reference to table `chapter`.

Image Image

Two entity class are `ChapterEntity.class` refer to table `chapter` and `ChapterTitle1Entity.class` refer to table `chapter_title_1`. There is a List<ChapterTitle1Entity> chapterTitle1EntityList in `ChapterEntity.class` annotated with `@OneToMany`. I want to get a list of `ChapterEntity` ordered by ChapterEntity.sequence asc and a list of `ChapterTitle1Entity` in each item of `ChapterEntity` ordered by `ChapterTitle1Entity.sequence` desc.

Originally, I use Criteria to query, but someone told me that order by may be not applies to child collection. so I change to use `@orderby annotation` but the embarrassing thing is sometimes I want to obder by `ChapterTitle1Entity.sequence` desc and sometimes I want to order by `ChapterTitle1Entity.sequence` asc.
Could anybody help me to achieve this. THANKS IN ADVANCE!

PS:
I am a newer to hibernate and don't want to improve any performance, I just want to solve this problem


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.