Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with session

 
ramusrila reddy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i am new user of hibernate.
when i am tryimng to connect to the back end its giving this exception.
my code is look like this
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.MappingException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.*;
import java.util.*;
public class HibernateUtil{

public void connect() throws HibernateException
{
try
{
System.out.println("Class claeed");

Configuration cfg = new Configuration();
//cfg.addClass(Emp.class);

System.out.println("Confg over");
SessionFactory sf = cfg.configure().buildSessionFactory();

System.out.println("Session Over");

Session hSession = sf.openSession();//Exception is rising over here

System.out.println("Session open");

Query q = hSession.createQuery("from emp e");
System.out.println("Query Fired");
q.setFirstResult(1);

q.setMaxResults(30);

List l=q.list();
Emp emp= (Emp)l.get(0);
System.out.println("Emp Name==>"+emp.getName());


}catch(Exception e)
{
System.out.println("Error==>"+e.toString());
}

}

public static void main(String[] args)
{
HibernateUtil utl=new HibernateUtil();
try
{
utl.connect();
}catch(Exception e)
{
System.out.println("Error==>"+e.toString());
}

}

}

Java.lang.NoClassDefFoundError: javax/transaction/Synchronization
at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:312)
at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:325)
at net.sf.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:333)
at HibernateUtil.connect(HibernateUtil.java:31)
at HibernateUtil.main(HibernateUtil.java:60)
Exception in thread "main"
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like a classpath issue ramusrila reddy. Make sure you have J2EE.jar in your classpath.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!