i have this bean
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;
}
i want to return all data order by id
getCurrentSession().createCriteria(Advertisement.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.addOrder(Order.asc("adPkId")).list();
the data in table take ids from 1 to 7
the data returned in list not order that return ids (3 – 4 – 5 – 6 – 7 – 1 – 2)
how to fix it
the problem come from
i change fetch = FetchType.EAGER to be lazy