• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting data using Hibernate

 
Ingoba Ningthoujam
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am new in Hibernate,Pliz somebody tell me to how to select data from table using Hibernate.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The documentation covers this. What have you tried? What is confusing you?
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
This is an excellent use cases here
http://www.makemyinfo.com/Tutorial.do?action=getTutorial&tutId=T0005.jsp
Rashid
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be a little careful with the link that Rashid posted, while most of it is a good example to see, there are a couple bad practices in there, including probably wanting to use try catches around your unit of works.

Mark
 
krish bhadragiri
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e.g (say you have a employee table in a database.and you have mapped that employee table with Employee.hbm.xml in hibernate to the Employee.java persistent class.then use the following code to select details from table.
note:u have to keep the Employee.hbm.xml in the classpath of persistent class.and give that description of mapping file .hibernate.cfg.xml)

List<Employee> employees=null;
try
{
Configuration config=new Configuration();
config=config.configure();
SessionFactory sessionFactory = config.buildSessionFactory();

Session session = sessionFactory.openSession();
Query q=session.createQuery("from Employee as emp");
System.out.println(q.getQueryString());
employees=q.list();



}
catch(HibernateException ex)
{
ex.printStackTrace();
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic