-->
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.  [ 3 posts ] 
Author Message
 Post subject: Schema Export failed with Null Pointer Exception
PostPosted: Sun Mar 18, 2007 6:32 pm 
Newbie

Joined: Sun Mar 18, 2007 6:11 pm
Posts: 4
Location: India
Hi all,

I was trying to Export Schema to my MySQL installation using an ant-task when the whole thing failed giving a NullPointerExcetion :-(

My apologies if you see any bad prctice/silly mistake. I am pretty new to Hibernate.

There are two classes Event and Location, for a simple calendar min-project. Event is supposed to contain instances of Location.
For sake of ease I have posted hbm.xml of both Location and Event.

I fail to understand why is the schema export is failing.
Thanks in advance.

Hibernate version:
3.2

Name and version of the database I am using:
MySQL 5.0

Mapping documents:
hibernate.cfg.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>
       <property name="connection.username">
         root
      </property>
      
       <property name="connection.password">
         abc@123
      </property>
      
       <property name="connection.url">
         jdbc:mysql://localhost/events_calendar
      </property>
      
      <property name="connection.driver_class">
         com.mysql.jdbc.Driver
      </property>
      
       <property name="dialect">
         org.hibernate.dialect.MySQLDialect
      </property>

       <mapping resource="com/manning/hq/ch04/Event.hbm.xml"/>
       <mapping resource="com/manning/hq/ch04/Location.hbm.xml"/>

   </session-factory>
</hibernate-configuration>


Location.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.manning.hq.ch04">
   <class name="Location" table="locations">
      <id name="id" column="uid" type="long">
         <generator class="native"/>
      </id>
      <property name="name" type="string"/>
      <property name="address" type="string" />
   </class>
</hibernate-mapping>



Event.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping package="com.manning.hq.ch04">
   <class name="Event" table="events">
      <id name="id" column="uid" type="long">
         <generator class="native"/>
      </id>
      <property name="name" type="string"/>
      <property name="startDate" column="start_date" type="date"/>
      <property name="duration" type="integer" />
      <many-to-one name="location" column="location_id" class="Location"/>
   </class>
</hibernate-mapping>


Ant File
Code:
<?xml version="1.0" ?>
<project name="build.xml" default="build" basedir=".">
   
   <!-- properties -->
   <property name="src.java.dir"      value="src/java"/>
   <property name="build.classes.dir" value="build/classes"/>
   <property name="hibernate.version" value="3.2"/>
   <property name="hibernate.lib.dir" location="H:\hibernate-${hibernate.version}"/>

   <property name="mysql.jdbc.version" value="5.0.4"/>
   <property name="jdbc.lib.dir"       location="H:\apache\zips"/>
   <property name="jdbc.driver.jar"    value="${jdbc.lib.dir}/mysql-connector-java-${mysql.jdbc.version}-bin.jar"/>
   
   <!-- Defines classpath with Hibernate and all its jars -->
   <path id="hibernate.lib.path">
      <fileset dir="${hibernate.lib.dir}/lib">
         <include name="**/*.jar"/>
      </fileset>
      <fileset dir="${hibernate.lib.dir}">
         <include name="hibernate3.jar"/>
      </fileset>
   </path>

   <!-- define classpath -->
   <path id="project.classpath">
      <pathelement location="${build.classes.dir}"/>
   </path>
   
   <path id="runtime.classpath">
      <path refid="project.classpath"/>
      <path refid="hibernate.lib.path"/>
      <pathelement location="${jdbc.driver.jar}"/>
      <pathelement location="${src.java.dir}"/>
   </path>   
   
   <!-- folders creation -->
   <target name="init">
      <mkdir dir="${build.classes.dir}"/>
      <echo message="Done"/>
   </target>
   
   <!-- compilation -->
   <target name="compile" depends="init">
      <javac srcdir="${src.java.dir}"
         debug="on"
         destdir="${build.classes.dir}" >
         <classpath refid="hibernate.lib.path"/>
      </javac>
   </target>
   
   <!-- execute class -->
   <target name="build" depends="compile">
      <java    classname="com.manning.hq.ch04.EventLoader"
            failonerror="true">
            <classpath refid="runtime.classpath"/>
      </java>
   </target>

   <!-- Clean Up -->
   <target name="clean">
      <delete dir="${build.classes.dir}"/>
   </target>
   
   <target name="schema-export" depends="compile">
      <taskdef name="schemaexport"
         classname="org.hibernate.tool.hbm2ddl.SchemaExportTask">
         <classpath refid="runtime.classpath"/>
      </taskdef>
      <schemaexport config="${src.java.dir}/hibernate.cfg.xml"/>
   </target>
   
</project>



Full stack trace of any exception that occurs:
Code:
$ ant -verbose schema-export
Apache Ant version 1.6.5 compiled on June 2 2005
Buildfile: build.xml
Detected Java version: 1.5 in: c:\Progra~1\Java\jdk1.5.0_09\jre
Detected OS: Windows XP
parsing buildfile H:\WORKSPACE\calendar\build.xml with URI = file:///H:/WORKSPACE/calendar/build.xml
Project base dir set to: H:\WORKSPACE\calendar
Build sequence for target(s) `schema-export' is [init, compile, schema-export]
Complete build sequence is [init, compile, schema-export, clean, build, ]

init:
     [echo] Done

compile:
    [javac] com\manning\hq\ch02\EventCalendar.java omitted as com/manning/hq/ch02/EventCalendar.class is up to date.
    [javac] com\manning\hq\ch04\Event.hbm.xml skipped - don't know how to handle it
    [javac] com\manning\hq\ch04\Event.java omitted as com/manning/hq/ch04/Event.class is up to date.
    [javac] com\manning\hq\ch04\EventLoader.java omitted as com/manning/hq/ch04/EventLoader.class is up to date.
    [javac] com\manning\hq\ch04\Location.hbm.xml skipped - don't know how to handle it
    [javac] com\manning\hq\ch04\Location.java omitted as com/manning/hq/ch04/Location.class is up to date.
    [javac] hibernate.cfg.xml skipped - don't know how to handle it

schema-export:
[schemaexport] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[schemaexport] log4j:WARN Please initialize the log4j system properly.

BUILD FAILED
H:\WORKSPACE\calendar\build.xml:69: java.lang.NullPointerException
        at org.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:158)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.tools.ant.Target.performTasks(Target.java:369)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
        at org.apache.tools.ant.Main.runBuild(Main.java:668)
        at org.apache.tools.ant.Main.startAnt(Main.java:187)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: java.lang.NullPointerException
        at org.hibernate.tool.hbm2ddl.SchemaExportTask.getSchemaExport(SchemaExportTask.java:218)
        at org.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:146)
        ... 12 more
--- Nested Exception ---
java.lang.NullPointerException
        at org.hibernate.tool.hbm2ddl.SchemaExportTask.getSchemaExport(SchemaExportTask.java:218)
        at org.hibernate.tool.hbm2ddl.SchemaExportTask.execute(SchemaExportTask.java:146)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.tools.ant.Target.performTasks(Target.java:369)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
        at org.apache.tools.ant.Main.runBuild(Main.java:668)
        at org.apache.tools.ant.Main.startAnt(Main.java:187)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)

Total time: 4 seconds
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 8:37 am 
Newbie

Joined: Sun Mar 18, 2007 6:11 pm
Posts: 4
Location: India
Hi,
I figured it out myself.
The problem was with the ant task defined.

I searched on internet and reconfigured the schema-export task to :

Code:
   
   <target name="schema-export" depends="compile">
      <taskdef classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
               classpathref="runtime.classpath"
               name="schemaexport"/>
     
      <schemaexport drop="false"
                    config="${build.classes.dir}/hibernate.cfg.xml"
                    output="schema-export.sql"
                    quiet="false"
                    text="false">
       
      </schemaexport>
    </target>


This got the schema export up and working, though I do not understand it fully. But when I do - I'll post a reply here :-)

Cheers :-D
- Amit Kumar Sharma


Top
 Profile  
 
 Post subject: Re: Schema Export failed with Null Pointer Exception
PostPosted: Tue Dec 15, 2009 4:41 pm 
Newbie

Joined: Tue Dec 15, 2009 4:35 pm
Posts: 4
Amit,

Thank you so much for this. I am working through the exact same book as you are and was having the same problem. I had only been searching for 2 days when I finally came across your post! I signed up just to say thanks (ok, maybe signing up for Hibernate forum when working on hibernate might be useful, just maybe)

Anyway, thanks again.

Edit: yeah, off course, after 2 days, I find 2 solutions to that problem. You could keep the same taskdef, and just add an output attribute to the <schemaexport> as follow:
Code:
   <target name="schema-export" depends="compile">
      <taskdef name="schemaexport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask" classpathref="hibernate.lib.path">
         <classpath refid="runtime.classpath" />
      </taskdef>
      <schemaexport config="${src.java.dir}/hibernate.cfg.xml" output="expout.txt" /> <!-- output attr. added here -->
   </target>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.