-->
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.  [ 8 posts ] 
Author Message
 Post subject: NullpointerException with CodeGenerator
PostPosted: Wed Apr 21, 2004 11:58 am 
Regular
Regular

Joined: Wed Apr 21, 2004 10:57 am
Posts: 62
Location: Hasselt, Belgium
When running CodeGenerator to convert my hbm.xml files into java files. I get the following Exception. With the ant build the result is the same. Am I forgetting something? Any ideas?

Exception
17:47:03,453 INFO Generator:95 - Generating 1 in D:\Applicatie\development\WEB-INF\build\gen-src\
java.lang.NullPointerException
at net.sf.hibernate.tool.hbm2java.BasicRenderer.isPropertySet(BasicRenderer.java:611)
at net.sf.hibernate.tool.hbm2java.BasicRenderer.generateConcreteEmptyClasses(BasicRenderer.java:332)
at net.sf.hibernate.tool.hbm2java.BasicRenderer.render(BasicRenderer.java:59)
at net.sf.hibernate.tool.hbm2java.Generator.write(Generator.java:138)
at net.sf.hibernate.tool.hbm2java.Generator.writeRecur(Generator.java:115)
at net.sf.hibernate.tool.hbm2java.Generator.generate(Generator.java:104)
at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:125)
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:324)
at com.intellij.rt.execution.application.AppMain.main(Unknown Source)


One of my mapping files.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!-- Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class name="test.hibernate.Land" table="land" >
<meta attribute="class-description" inherit="false">
@hibernate.class
table="land"
</meta>

<id name="id" type="java.lang.String" column="Id">
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
type="java.lang.String"
column="Id"
</meta>
<generator class="assigned" />
</id>

<property name="code" type="java.lang.String" column="Code" not-null="true" unique="true" length="3">
<meta attribute="field-description">
@hibernate.property
column="Code"
length="3"
not-null="true"
</meta>
</property>

<property name="naam" type="java.lang.String" column="Naam" length="35">
<meta attribute="field-description">
@hibernate.property
column="Naam"
length="35"
</meta>
</property>

<!-- associations -->

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 21, 2004 6:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
a bug in the current release requires you to point to a config.xml file via the commandline.

search the docs + forum for more instructions

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 3:50 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
max wrote:
a bug in the current release requires you to point to a config.xml file via the commandline.

search the docs + forum for more instructions


I.e.: if you are using ANT to launch hbm2java you need to use the hbm2java config attribute to pass the tool an xml file with the following inside:

<codegen>
<generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
</codegen>

if you are using the commandline version I believe you must use --config but I'm not sure since this was not my case.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 3:51 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
immanuel wrote:
max wrote:
a bug in the current release requires you to point to a config.xml file via the commandline.

search the docs + forum for more instructions


I.e.: if you are using ANT to launch hbm2java you need to use the hbm2java config attribute to pass the tool an xml file with the following inside:

<codegen>
<generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
</codegen>

if you are using the commandline version I believe you must use --config but I'm not sure since this was not my case.


But remark there's another bug in the current hbm2java version which causes wrong equals() generation, so you may probably want to patch hbm2java before using it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 4:47 am 
Regular
Regular

Joined: Wed Apr 21, 2004 10:57 am
Posts: 62
Location: Hasselt, Belgium
Thanks for the replies. But it still throws the same exception. I did already place the config option in my ant task the previous time.

So I still make a mistake somewhere. Question is: where?

build.xml
Code:
<target name="hbm2java" description="Generate .java from .hbm files." depends="compile-hibernate">
       
  <mkdir dir="${build.gen-src.dir}"/>
  <taskdef
    name="hbm2java"
    classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
    classpathref="lib.class.path"
  />
     
  <hbm2java output="${build.gen-src.dir}" classpathref="lib.class.path" config="D:/Applicatie/development/WEB-INF/build/classes/hibernate.cfg.xml">
    <fileset dir="${build.gen-src.dir}">
      <include name="**/*.hbm.xml"/>
    </fileset>
  </hbm2java>
       
</target>


hibernate.cfg.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
    <session-factory>

        <property name="connection.url">jdbc:mysql:///ngb</property>
        <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.username">root</property>
        <property name="connection.password" />
        <property name="show_sql">false</property>
        <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

        <mapping resource="test/hibernate/Gebruiker.hbm.xml" />
        <mapping resource="test/hibernate/Gebruikerrol.hbm.xml" />
        <mapping resource="test/hibernate/Klasse.hbm.xml" />
        <mapping resource="test/hibernate/Land.hbm.xml" />
        <mapping resource="test/hibernate/Periode.hbm.xml" />
        <mapping resource="test/hibernate/Ploeg.hbm.xml" />
        <mapping resource="test/hibernate/Ploegrenner.hbm.xml" />
        <mapping resource="test/hibernate/Puntentabel.hbm.xml" />
        <mapping resource="test/hibernate/Renner.hbm.xml" />
        <mapping resource="test/hibernate/Uitslag.hbm.xml" />
        <mapping resource="test/hibernate/Wedstrijd.hbm.xml" />

        <codegen>
            <generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
        </codegen>

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 4:51 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
Uhm, not sure you must make it point to an hibernate.cfg.xml!!! The xml I've pasted is the same exact xml I have in my hbm2java-config.xml, and it's that file I give it in the config option.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 5:01 am 
Regular
Regular

Joined: Wed Apr 21, 2004 10:57 am
Posts: 62
Location: Hasselt, Belgium
I've just tried it with the hbm2java config like you said. And it worked. Thanks!
So I guess putting it in my hibernate.cfg.xml was the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 5:06 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
GG_Peter wrote:
I've just tried it with the hbm2java config like you said. And it worked. Thanks!
So I guess putting it in my hibernate.cfg.xml was the problem.


Yes, hbm2java has a different config structure.


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