order in hibernate

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

Answers


the problem come from

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

i change fetch = FetchType.EAGER to be lazy


Need Your Help

Open source HTTP or HTTPS proxy

proxy https

I want to log all HTTP requests made by the browser to a file, so I thought I can run a HTTP/S proxy locally and do this. However, the proxies at proxies.xhaus.com/ don't meet my needs - either no ...

Perform action on clicking a tooltip

javascript jquery html css

I need to show tooltip when a div is hover on. By clicking that tooltip, I need to execute some action. This similar to Gmail's compose mail. It shows the formatting options on clicking A icon.