Hi. I am trying to execute a basic JUnit (3.8.1) test case, inside of Eclipse 3.2.0, that initializes a Hibernate configuration, as you see in the SessionFactory code below. I have included the hibernate.cfg.xml that is being parsed. The test case only executes the one line of code that you see below.
If I place hibernate.cfg.xml in the project root, I get a NullPointerException. If I place the hibernate.cfg.xml in the src folder of the Eclipse project, I get a: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml. I have listed both exceptions below.
I have been able to successfully run JUnit tests in the past within Eclipse that execute Hibernate queries, but I am having trouble getting it to work now...
Does anybody else execute JUnit test cases which execute Hibernate code? I tried to make the hibernate.cfg.xml as simple as possible with just one mapping file...
One other note - the code will execute correctly if it runs within a JBoss server (it does not run as a JUnit test case in this context). I just can't config to initialize within eclipse.
Thank you.
Hibernate version: 3.2.0
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="SessionFactory">
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">password</property>
<property name="hibernate.connection.url">my_db_connection_string</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.default_schema">myschema</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<mapping resource="HibernateMapping/test.hbm.xml" />
</session-factory>
</hibernate-configuration>
Code between sessionFactory.openSession() and session.close():
SessionFactory sessionFactory = new Configuration()
.configure()
.buildSessionFactory();
Full stack trace of any exception that occurs:
-------------------------------------------------------------
Here is the NullPointerException stack trace:
-------------------------------------------------------------
08:27:10,368 INFO Environment:500 - Hibernate 3.2.0.ga
08:27:10,380 INFO Environment:518 - loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false}
08:27:10,384 INFO Environment:667 - Bytecode provider name : cglib
08:27:10,389 INFO Environment:584 - using JDK 1.4 java.sql.Timestamp handling
08:27:10,412 INFO Configuration:1350 - configuring from resource: /hibernate.cfg.xml
08:27:10,413 INFO Configuration:1327 - Configuration resource: /hibernate.cfg.xml
java.lang.NullPointerException
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:144)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1329)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1351)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
at testcases.TestHibernateConfig.testCreateHibernateConfig(TestHibernateConfig.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
--------------------------------------------------------------------------------------------------------
Here is the HibernateException stack trace when I place the config file in the src folder:
--------------------------------------------------------------------------------------------------------
08:53:21,119 INFO Environment:500 - Hibernate 3.2.0.ga
08:53:21,129 INFO Environment:518 - loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false}
08:53:21,133 INFO Environment:667 - Bytecode provider name : cglib
08:53:21,140 INFO Environment:584 - using JDK 1.4 java.sql.Timestamp handling
08:53:21,181 INFO Configuration:1350 - configuring from resource: /hibernate.cfg.xml
08:53:21,182 INFO Configuration:1327 - Configuration resource: /hibernate.cfg.xml
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1418)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1352)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1338)
at testcases.TestHibernateConfig.testCreateHibernateConfig(TestHibernateConfig.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.dom4j.DocumentException: null Nested exception: null
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1408)
... 23 more
Name and version of the database:
Oracle 10g
|