Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.ExceptionInInitializerError at org.hibernate.cfg.Configuration.reset(Configuration.java:)

 
Sameer Kunder
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam trying simple hibernate standalone program which inserts data into Oracle DB. When i ran the program testContact i get below error.

Your help is highly appreciated.

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Inside finally...
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.hibernate.cfg.Configuration.reset(Configuration.java:332)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:298)
at org.hibernate.cfg.Configuration.<init>(Configuration.java:302)
at com.verizon.hibernate.model.testContact.main(testContact.java:17)
Caused by: java.lang.NullPointerException
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:167)
at org.hibernate.cfg.Environment.<clinit>(Environment.java:618)
... 4 more

Iam using Eclipse, tomcat 6, and hibernate 3.6.10. Iam having all the hibernate config files correct i.e. hibernate.cfg.xml and contact.hbm.xml
Below is the java code.

Contact.java
=================

package com.sam.web;

public class Contact {

private String firstName;
private String lastName;
private String email;
private int id;
// private String create_date;

public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
public int getId() {
return id;
}

public void setFirstName(String string) {
firstName = string;
}
public void setLastName(String string) {
lastName = string;
}
public void setEmail(String string) {
email = string;
}
public void setId(int l) {
id = l;
}
}

testContact.java
===========
package com.sam.hibernate.model;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class testContact {
public static void main(String[] args) {

Session session = null;
System.out.println("Inside testContact.java");


try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object

Transaction tx = session.beginTransaction();

System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(5);
contact.setFirstName("Samuel");
contact.setLastName("Roger");
contact.setEmail("sam@gmail.com");
session.save(contact);
tx.commit();

System.out.println("Done: Id: "+ contact.getId() + ", firstName:"+contact.getFirstName() +", lastName: "+contact.getLastName() + ", email: "+ contact.getEmail());

/*Query query = session.createQuery("insert into Stock(stock_code, stock_name)" +
"select stock_code, stock_name from backup_stock");
int result = query.executeUpdate();*/

}catch(Exception e){
System.out.println(e.getMessage());
System.out.println("Inside exception...");
}finally{
// Actual contact insertion will happen at this step
//session.flush();
//session.close();

}

}
 
Manuel Petermann
Ranch Hand
Posts: 177
Hibernate Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need a slf4j binder in your classpath.
 
Sameer Kunder
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

I already have have below ones in my build path, do i need to add any other slf4jxx.jar?

hibernate3.jar

hibernate-distribution-3.6.10.Final\lib\required
-------------------------------------------------
slf4j-api-1.6.1.jar
jta-1.1.jar
javassist-3.12.0.GA.jar
dom4j-1.6.1.jar
commons-collections-3.1.jar
antlr-2.7.6.jar

hibernate-distribution-3.6.10.Final\lib\jpa
--------------------------------------------
hibernate-jpa-2.0-api-1.0.1.Final.jar

hibernate-distribution-3.6.10.Final\lib\bytecode\javassist
------------------------------------------------------------
javassist-3.12.0.GA.jar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic