aspose file tools*
The moose likes Object Relational Mapping and the fly likes Doubt in Hibernate Sample Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Doubt in Hibernate Sample Application" Watch "Doubt in Hibernate Sample Application" New topic
Author

Doubt in Hibernate Sample Application

Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi all,

I have coded one sample application using hibernate framework. The main aim of this application is to insert some data to the table. But I am getting the below mentioned exception:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:152)
at com.Hibernate.Demo.FirstHibernateProgram.main(FirstHibernateProgram.java:15)


code for FirstHibernateProgram.java

package com.Hibernate.Demo;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class FirstHibernateProgram
{
public static void main(String[] args)
{
Session ses = null;

try
{
System.out.println("Im inside try block!!");
Configuration cf = new Configuration();
cf = cf.configure();

SessionFactory sesFact =cf.buildSessionFactory();
ses = sesFact.openSession();
System.out.println("inserting records into STUDENT tbl");
student stu = new student();
stu.setRegno(3014);
stu.setName("Keerthi Kumar N");
stu.setCourse("MCA");
ses.save(stu);
System.out.println("Records inserted !!");
}
catch(Exception e)
{
e.getMessage();
}
finally
{
//ses.flush();
//ses.close();
}
}
}

Thanks,
Keerthi Kumar N


Cheers,
Keerthi Kumar N
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
You need a logger implementation for slf4j => http://www.slf4j.org/
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi,

Hi added those sl4j jar files.. but still no go.. still i am getting the same exception as mentioned above!!

please help me.

Thanks,
Keerthi Kumar N
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Where did you add them? The error means they are not on the classpath.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi,

I added those jar files into the lib folder of my application.I have set the class build path as well.

Please help me !

Thanks,
Keerthi Kumar N
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well the error is still because the jar file is not on your classpath. Thismay help.
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi,

I am doing this through the Eclipse Configure build path option to set the class path. But still no go !!

Thanks,
Keerthi Kumar N
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
Which JARs are on the classpath?
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi,

All the required JARS I have placed in the class path !! loggin n SL4J jars as well

Thanks,
Keerthi Kumar N
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

We are not trying to be critical here, Keerthi, but if that were accurate you would not see this error message.

In order for us to be able to help, could you possibly tell use exactly what jars files are where?
sujith Acharya
Ranch Hand

Joined: Dec 25, 2006
Posts: 60
slf4j requires jars like ant-antlr, antlr, commons-lang .. see if these jars are in your class-path.
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi,

I have all the jars mentioned earlier.. but still no go. Also to inform you people that I am using MS Access Database as well. Please fine my hibernate.cfg.xml file below:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>
<property name="hibernate.connection.url">jdbcdbc:STUDENT</property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="student.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Please do the needful.

Thanks,
Keerthi Kumar N
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
The exception is a ClassNotFoundException that tells you the classname of the missing class. It's a class from slf4j so please give us the names of ALL jars in the classpath. By the way: Telling Hibernate to speak MySQL to an Access-DB is wrong.
Keerthi Kumar
Ranch Hand

Joined: Apr 20, 2009
Posts: 105
Hi,

I have used the below mentioned jar files in my sample application:

antlr-2.7.5H3.jar, c3p0-0.9.1.jar, cglib-2.2.jar, commons-logging.jar, dom4j-1.6.1.jar, hibernate3.jar, jta.jar, log4j-1.2.9.jar, log4j-over-slf4j-1.5.8.jar, slf4j-api-1.5.8.jar, slf4j-log4j12-1.5.8.jar, slf4j-log4j12-1.5.8-sources.jar

Also please guide me how to use MS Access DB in the hibernate application.

Thanks,
 
 
subject: Doubt in Hibernate Sample Application