开发者

Can I define a default order for an @Entity?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜