I\'m trying to print ordered list after persisting it and retrieving.
My Entities:
@Entity
public class News {
@Id @GeneratedValue
private Long i
I guess that you are getting your entity from the entity manager and not from db, so you are getting the same object that you created (not sorted object). You should try to refresh caché before the em.find()
method:
em.getTransaction().begin();
em.persist(n1);
em.getTransaction().commit();
// Clear object
em.getEntityManagerFactory().getCache().evict(News.class, n1.getId());
// find
News news = em.find(News.class, n1.getId());
for (int i=0; i
From Javadoc, the method:
T find(java.lang.Class entityClass, java.lang.Object primaryKey)
Find by primary key. Search for an entity of the specified class and primary key. If the entity instance is contained in the persistence context, it is returned from there.
I empathize the part that maybe is getting you troubles.