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...
|