开发者

Can I define a default order for an @Entity?

开发者 https://www.devze.com 2023-02-28 21:54 出处:网络
For example, @Entity class Foo { @Id 开发者_运维问答int id; @Column(nullable = false) int priority;

For example,

@Entity
class Foo {

    @Id
 开发者_运维问答   int id;

    @Column(nullable = false)
    int priority;
    ...
}

I want HibernateTemplate.loadAll(Foo.class) to order by priority by default, is it possible with annotations?


No, it's not possible. Generally annotations are not supposed to affect queries that return a list of entities (annotations affect the behaviour of a single entity)

You can use an HQL/JPQL query to get ordered entities:

 SELECT f FROM Foo f ORDER BY f.priority
0

精彩评论

暂无评论...
验证码 换一张
取 消