Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Select random rows in JQPL or JPA

MrBabakishiyevJul 22 2011 — edited Jul 22 2011
Hello.
I have CardResource entity. And in database created Card_Resource table.
I want to select random 5 rows from this Entity.

I did that

List<CardResource> result;
Query query = entityManager.createQuery("SELECT e FROM CardResource e ORDER BY RAND() ");
result = query.setMaxResults(5).getResultList();

But this gave me exceptions.

Thanks for attention
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 19 2011
Added on Jul 22 2011
2 comments
5,754 views