hibernate条件查询顺序按连接表字段

时间:2016-09-19 12:24:10

标签: hibernate sql-order-by hibernate-criteria jointable

我使用mysql数据库并有两个表chapter_title_1chapter_id,表chapter_title_1中有一个fk chapter引用表ChapterEntity.class

table chapter table chapter_title_1

两个实体类chapter引用表ChapterTitle1Entity.classchapter_title_1引用表List<ChapterTitle1Entity> chapterTitle1EntityListChapterEntity.class@OneToMany注明了ChapterEntity。我希望获得ChapterEntity.sequenceChapterTitle1Entity 排序的ChapterEntity列表以及ChapterTitle1Entity.sequence的每个Criteria criteria = session().createCriteria(ChapterEntity.class, "chapter"); criteria.createAlias("chapter.chapterTitle1EntityList", "title1List"); criteria.addOrder(Order.asc("chapter.sequence")). addOrder(Order.desc("title1List.sequence")); List<ChapterEntity> chapterEntityList = criteria.list(); return chapterEntityList; 列表addOrder(Order.desc("title1List.sequence") } desc

在我的ADO层中,我使用条件来查询我的数据库。我使用以下代码获取列表:

addOrder(Order.asc("title1List.sequence")

但无论是ChapterTitle1Entity还是 Regex reg = new Regex(@"[^a-zA-Z]"); var result = input.OrderBy(x => reg.Replace(x, string.Empty)).ToArray(); ,列表 var input = new List<string>(); input.Add("(c"); input.Add("*b"); input.Add("_a"); Regex reg = new Regex(@"[^a-zA-Z]"); var result = input.OrderBy(x => reg.Replace(x, string.Empty)).ToArray(); 的顺序都保持不变。

1 个答案:

答案 0 :(得分:0)

您可以这样做:

TITLE 1
Did this and that.
c:\abc\def\test4.txt

TITLE 2
Did this and that.
c:\aaa\bbb\ccc\test5.txt

但是代码将成为列表中的全部。