JPA / Hibernate – @OrderBy 随机

huangapple 未分类评论56阅读模式
英文:

JPA / Hibernate - @OrderBy random

问题

我有一个JpaRepository类和具有OneToMany单向关系的实体。我尝试使用@OrderBy注解,但它没有起作用。我需要列表项以随机顺序排列。

@Entity
public class Foo {

@OneToMany
@JoinColumn(name = "foo_id")
@OrderBy("function('RAND')")
private List<Bar> bars;

}
英文:

I have JpaRepository class and entities with OneToMany unidirectional relationship. I tried to use the @OrderBy annotation but it didn't work. I need the list items to be in random order.

@Entity
public class Foo {

@OneToMany
@JoinColumn(name = &quot;foo_id&quot;)
@OrderBy(&quot;function(&#39;RAND&#39;)&quot;)
private List&lt;Bar&gt; bars;

}


</details>


huangapple
  • 本文由 发表于 2020年6月29日 05:07:20
  • 转载请务必保留本文链接:https://java.coder-hub.com/62628236.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定