This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Problem with session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with session" Watch "Problem with session" New topic
Author

Problem with session

ramusrila reddy
Greenhorn

Joined: May 06, 2004
Posts: 1
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

Joined: Apr 14, 2004
Posts: 10336

Looks like a classpath issue ramusrila reddy. Make sure you have J2EE.jar in your classpath.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem with session
 
Similar Threads
java.net.SocketException: Broken pipe
Getting HibernateException: Errors in named queries
Hibernate cfg xml and Eclipse problem
java.lang.NoSuchMethodError
Hibernate help