0

I've set up and am running Hibernate 3.6 on Eclipse/Juno EE.

My first code is giving me a runtime error on instantiating the class Configuration of HN. So-- to be precise,

SessionFactory aFactory;
Configuration conf; 

are fine & running,

but the line next below

conf=new Configuration();

is throwing java.lang.ExceptionInInitializerError.

The code

SessionFactory aFactory = new Configuration().configure().buildSessionFactory(); 

is nowhere near running.

My hibernate.cfg.xml is as follows:

<?xml version='1.0' encoding='utf-8'?>


<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
    <property name="connection.driver_class">org.postgresql.Driver</property>       
    <property name="connection.url">jdbc:postgresql://localhost:5432/ThisDB</property>  
    <property name="connection.username">postgres</property>
    <property name="connection.password">somePass</property>
    <property name="connection.pool_size">1</property>
    <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>  
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <property name="show_sql">true</property>
    <property name="hbm2ddl.auto">create</property>
    <mapping class="dataObjs.someItems"/>  
</session-factory>
</hibernate-configuration>

I copied the contents of the "!DOCTYPE" tag from a project in the same pack I downloaded-- so it should be fine.

My libraries are all added to the project and are imported in the class.

The code is not giving any such errors on creation of "non-Hibernate" objects.

What am i missing?

New to HN. this my first code.

//=====================================

EDIT: Adding the code & the stacktrace:

package somePaket;

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

import dataObjs.someItems;

public class firstClass{
public static void main(String[] args) {
    System.out.println("..........see this.........");

    someItems kullanici = new someItems();
    itm.setID(1);
    itm.setType("aaa");

    SessionFactory aFactory;
    Configuration conf=new Configuration();;

    new Configuration();
    new Configuration().configure().buildSessionFactory();
}
}

the full log on Console:

..........see this.........
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.
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 somePaket.firstClass.main(firstClass.java:18)
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

//=====================

EDIT2:

Traced it in Debugger:

LoggerFactory.singleImplementationSanityCheck()

is throwing the following at its line 216:

FileNotFoundException(Throwable).<init>(String) line: 264. 
2
  • Post the whole stacktrace Commented Jul 3, 2013 at 19:34
  • the log on Console-- i guess that's what you were asking for Commented Jul 3, 2013 at 19:56

2 Answers 2

1

You may have to include your slf4j library with the application:

slf4j-simple-1.6.2.jar
Sign up to request clarification or add additional context in comments.

2 Comments

those three "SLF4J:" lines are the exact same in the tutorial i'm following (and running the code fine). They also are the lines i saw in some other boards i saw looking around on internet for an answer to my error.
sorry that you didn't enjoy my comment. everything is a java Q. i don't think the Q should be crowded w/that.
0

You need to specify the resource path of your hibernate.cfg.xml

IIRC this is done in the configure() method of Configuration.

Edit: turns out there exists Configuration#configure() with no arguments. I guess this expects the hibernate.cfg.xml to be in the root classpath. Are you sure the resource is in your application classpath?

Edit2:

Looked up Hibernate 3.6.8 source. The NullPointer (if I got the version right) is on the following line

stream = Environment.class.getClassLoader().getResourceAsStream( stripped );

Looks like getClassLoader() returns null. The Class#getClassLoader() contract states that if the class was loaded by the bootstrap classloader this method may return null.

This happens if your jars are in the lib folder of your jre (specifically hibernate-core jar, in this case). Is that the case?

11 Comments

hibernate.cfg.xml is in /src folder along with the packages, so it shd be fine(?) i am following a tutorial and the entire code is from there. i don't think i missed anything in the configuration either.
i created a "HibernateLib" on Eclipse and put all the Hibernate jars, including Hibernate3.jar into that library. Then i defined "HibernateLib" in the project. in the end, "HibernateLib" is appearing right under the project main folder, in the same level as the JRE System Library and /src folder.
version i have here is 3.6.4 in case it matters
The line is the same in 3.6.4. Whatever method you use to include the library in eclipse, is it possible that the actual hibernate jars are located in the lib folder of the JRE you use to run your program with in the actual filesystem?
i haven't even stepped foot into jre folder in a while. jre & hibernate libs are two separate libraries on eclipse and defined them without modifying in the project. i used the "build-path" menu and followed the steps in doing these. besides, all these are the way they've been done in that tutorial of mine-- thats what beats me.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.