0

我有这个豆子

public class Advertisement{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "pkid", nullable = false)
    @Basic(fetch = FetchType.EAGER)
    private long adPkId;

    @Size(max = 50, message = "{long.value}")
    @Column(name = "Name", unique = true, nullable = false, length = 50)
    private String name;

    @Size(max = 255, message = "{long.value}")
    @Column(name = "Description", length = 255)
    private String description;
}

我想按 id 返回所有数据顺序

getCurrentSession().createCriteria(Advertisement.class)
                .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
                .addOrder(Order.asc("adPkId")).list();

表中的数据采用从 1 到 7 的 ID 列表中返回的数据不是返回 ID 的顺序 (3 - 4 - 5 - 6 - 7 - 1 - 2)

如何解决

4

1 回答 1

0

问题来自

@OneToMany(fetch = FetchType.EAGER, mappedBy = "advertisement", orphanRemoval = true, cascade = CascadeType.REMOVE)
    @OrderBy("name")
    private Set<test> test= new HashSet<test>(0);

我将 fetch = FetchType.EAGER 更改为懒惰

于 2012-07-15T15:36:20.350 回答