• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving multiple records using Hibernate

 
RoshaniG Gopal
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to search and display records from the Oracle DB using Hibernate for a particular search criterion like 'first_name'. There may be multiple records for the same as there is no primary key in the table. I want to use the Hibernate API for doing so. I am using JSF as view here.
===================================
public ArrayList getEmp(){

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session =sessionFactory.openSession();
Query query = session.createQuery("from Employee where first_name = :nameJsf");
query.setParameter("nameJsf", getFirst_name().toString());
ArrayList listRecords = (ArrayList) query.list();
return listRecords;

}
If I use the above approach, I get the same record iterated over the number of times it exisits in the DB. For eg, if i have 5 records by first_name of XYZ in DB but with diff last_name, I get the 1st record iterated 5 times. (There is no primary key in the table).

I have tried to use load() but i face an exception. Please guide me the approach to solve this issue. Thanks in advance.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is most likely an issue in your JSF page.

When you debug the code in a debugger, you cna look in your list and see the real five records in the array.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic