-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Errors testing Hibernate application using junit
PostPosted: Tue Jan 19, 2010 1:41 pm 
Newbie

Joined: Fri Nov 27, 2009 12:36 am
Posts: 2
Hello,
I've been fighting with this for far too long now and could use some assistance.

I'm trying to test an application using hibernate with junit. All of my test keep getting this error:
[junit] Testcase: testAddCodeGroup took 0.018 sec
[junit] Caused an ERROR
[junit] null
[junit] java.lang.NullPointerException
[junit] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1569)
[junit] at org.hibernate.cfg.Configuration.configure(Configuration.java:1557)
[junit] at org.bestprep.CodesImpl.addCodeGroup(CodesImpl.java:432)
[junit] at org.bestprep.CodesImplTest.testAddCodeGroup(CodesImplTest.java:131)
[junit]

With the help of a friend of mine, we substituted hibernate's original Configuration.Java with a modified version containing more output, here is what we found:

[junit] ------------- Standard Output ---------------
[junit] addCodeGroup
[junit] BOOM
[junit] doc name = HTML
[junit] doc parent = null
[junit] <?xml version="1.0" encoding="UTF-8"?>
[junit] <!DOCTYPE HIBERNATE-CONFIGURATION PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><HTML><HEAD/><BODY><HIBERNATE-CONFIGURATION>
[junit] <SESSION-FACTORY name="java:hibernate/session-factory">
[junit]
[junit] <!-- SQL dialect -->
[junit] <PROPERTY name="dialect">org.hibernate.dialect.MySQL5Dialect</PROPERTY>
[junit] <!-- Database connection settings -->
[junit] <PROPERTY name="connection.driver_class">com.mysql.jdbc.Driver</PROPERTY>
[junit] <PROPERTY name="connection.url">jdbc:mysql://localhost/openemergency</PROPERTY>
[junit] <PROPERTY name="connection.username">openem</PROPERTY>
[junit] <PROPERTY name="connection.password">openpass</PROPERTY>
[junit] <PROPERTY name="connection.shutdown">true</PROPERTY>
[junit]
[junit] <!-- SQL dialect -->
[junit] <!-- <property name="dialect">org.hibernate.dialect.HSQLDialect</property>
[junit] -->
[junit] <!-- Database connection settings -->
[junit] <!-- <property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
[junit] <property name="connection.url">jdbc:hsqldb:data/bestprep</property>
[junit] <property name="connection.username">sa</property>
[junit] <property name="connection.password"/>
[junit] <property name="connection.shutdown">true</property>
[junit] -->
[junit] <!-- JDBC connection pool (use the built-in one) -->
[junit] <PROPERTY name="connection.pool_size">1</PROPERTY>
[junit] <!-- Enable Hibernate's automatic session context management -->
[junit] <PROPERTY name="current_session_context_class">thread</PROPERTY>
[junit] <!-- Disable the second-level cache -->
[junit] <PROPERTY name="cache.provider_class">org.hibernate.cache.NoCacheProvider</PROPERTY>
[junit] <!-- Echo all executed SQL to stdout -->
[junit] <PROPERTY name="show_sql">true</PROPERTY>
[junit] <!-- disable batching so HSQLDB will propagate errors correctly. -->
[junit] <PROPERTY name="jdbc.batch_size">0</PROPERTY>
[junit]
[junit] <!-- List all the mapping documents we're using -->
[junit] <MAPPING resource="org/bestprep/data/AddressDB.hbm.xml"/>
[junit] <MAPPING resource="org/bestprep/data/CityStateZipDB.hbm.xml"/>
[junit] <MAPPING resource="org/bestprep/data/CityStateZipRec.hbm.xml"/>
[junit] <MAPPING resource="org/bestprep/data/CodeGroupDB.hbm.xml"/>
[junit] <MAPPING resource="org/bestprep/data/CodeItemsDB.hbm.xml"/>
[junit] <MAPPING resource="org/bestprep/data/CodeGroupRec.hbm.xml"/>
[junit] <!-- <mapping resource="org/bestprep/data/EventSchedule.hbm.xml"/> -->
[junit] <MAPPING resource="org/bestprep/data/FeeScheduleDB.hbm.xml"/>
[junit] <MAPPING resource="org/bestprep/data/FeeItemsDB.hbm.xml"/>
[junit] <MAPPING resource="org/bestprep/data/FeeScheduleRec.hbm.xml"/>
[junit] <MAPPING resource="org/bestprep/data/Members.hbm.xml"/>
[junit] <MAPPING resource="org/bestprep/data/Templates.hbm.xml"/>
[junit]
[junit]
[junit] <!-- <mapping resource="org/bestprep/data/SerialKey.hbm.xml"/> -->
[junit] <!-- <mapping resource="org/bestprep/data/Organizations.hbm.xml"/> -->
[junit] </SESSION-FACTORY>
[junit] </HIBERNATE-CONFIGURATION>
[junit]
[junit] </BODY></HTML>

As you will notice, it is my hibernate.cfg.xml file, that was modified (not by me) to contain HTML; this is instead of being read in as a straight XML file.

The errors point to the Configuration call. Here it is in my source code:
Query query;
CodeItemsDB itemsDB = null;
String returnValue = null;

// Create a configuration based on the XML file we've put
// in the standard place.
Configuration config = new Configuration();
// config.configure();
// SessionFactory sessionFactory; // Used to talk to Hibernate
SessionFactory sessionFactory = config.configure().buildSessionFactory(); // Used to talk to Hibernate

Session session;

The errors always point to the same place (above).

I have searched in any number of ways to find an answer, so far no joy. I've tried rewriting that code multiple ways also.

Any suggestions or ideas?

Thanks,

Harlan...


Top
 Profile  
 
 Post subject: Re: Errors testing Hibernate application using junit
PostPosted: Wed Jan 20, 2010 6:32 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Which version of hibernate are you using ?


Top
 Profile  
 
 Post subject: Re: Errors testing Hibernate application using junit
PostPosted: Wed Jan 20, 2010 10:45 am 
Newbie

Joined: Fri Nov 27, 2009 12:36 am
Posts: 2
Hello,
I'm using:
Hibernate 3.3.1.GA
Hibernate Tools 3.2.0.b9

If you need anything else, please let me know.

Thank You for your time and attention.

Harlan...


Top
 Profile  
 
 Post subject: Re: Errors testing Hibernate application using junit
PostPosted: Wed Jan 20, 2010 11:04 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
org.hibernate.cfg.Configuration.java in version 3.3.1GA does not contain any code at line 1569 (= the line where you get the NullPointerException), so either:
- you are using another version
- or you did already the first attempt with a locally modified version of org.hibernate.cfg.Configuration.java

Sorry, but as long you are using a locally modified version of org.hibernate.cfg.Configuration.java
without attaching the source code, nobody can help you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.