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
精彩评论