考虑以下带有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映射进行排序
发布评论