Hibernate:对ManyToMany映射进行排序

编程入门 行业动态 更新时间:2024-10-27 15:25:02
本文介绍了Hibernate:对ManyToMany映射进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

考虑以下带有JPA批注的映射

Consider the following mapping with JPA annotations

@ManyToMany(cascade = { CascadeType.ALL }) @JoinTable(name = "infotype_validations", joinColumns = { @JoinColumn(name = "info_type_id") }, inverseJoinColumns = { @JoinColumn(name = "validation_id") } ) @OrderBy(value="validation_id desc") public Set<Validation> getValidation() { return validation; }

我的意图是在数据库中建立一个可连接的数据库,每次在我的服务中调用getValidation()时,记录都会按validation_id的顺序返回.现在,为了测试我的功能,我使用了DbUnit.每次我启动一个测试类时,都会创建一个数据库,然后休眠创建我的表,然后DbUnit用数据填充它们.当我评论@OrderBy时,我的测试通过了,但是当我取消评论时,找不到表infotype_validations.我在网上查看了可用的文档,似乎在这种映射中完全有可能使用@OrderBy.那我想念什么?

My intention is to have a jointable in the database and each time the getValidation() is called in my services the records get returned ordered by validation_id. Now to test my functionality I make use of DbUnit. Each time I start a testclass my database gets created and hibernate creates my tables afterwhich DbUnit fills them with data. When I comment @OrderBy my tests pass but when I uncomment it, I get table infotype_validations can't be found. I've looked at the available documentation online and it seems it is perfectly possible to have @OrderBy in this kind of mapping. So what am I missing ?

推荐答案

您需要使用字段名而不是列名.

You need to use the field name not the column name.

//Assuming the field is validationId @OrderBy(value="validationId desc") public Set<Validation> getValidation() { return validation; }

还要确保infotype_validations表存在于数据库中并且拼写匹配.

Also make sure that the infotype_validations table exists within your database and the spelling matches.

更多推荐

Hibernate:对ManyToMany映射进行排序

本文发布于:2023-11-16 14:20:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605057.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Hibernate   ManyToMany

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!