-->
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.  [ 5 posts ] 
Author Message
 Post subject: one-to-many problem?
PostPosted: Sun Jan 11, 2004 8:14 am 
Newbie

Joined: Tue Aug 26, 2003 5:09 pm
Posts: 13
I have 2 objects, User and Message, User has a one-to-many relationship with Message. I scanned through <http://www.xylax.net/hibernate/onetomany.html> and made the code just lik described in the article:

User.hbm.xml
=======
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>

<class
name="users.User"
table="users"
>

<id
name="id"
type="java.lang.Integer"
column="id"
unsaved-value="-1"
>
<generator class="identity" />
</id>

<property
name="username"
type="java.lang.String"
column="username"
not-null="true"
length="32"
/>
<property
name="password"
type="java.lang.String"
column="password"
not-null="true"
length="32"
/>

<set role="messages" table="messages">
<key column="user_id"/>
<one-to-many class="Message"/>
</set>



</class>
</hibernate-mapping>
=======

Message.hbm.xml
=======
<?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>

<class
name="users.Message"
table="messages"
>

<id
name="id"
type="java.lang.Integer"
column="id"
unsaved-value="-1"
>
<generator class="identity" />
</id>

<property
name="message"
type="java.lang.String"
column="message"
not-null="true"
length="32"
/>
<property
name="receivedUtc"
type="java.sql.Timestamp"
column="received_utc"
not-null="true"
length="19"
/>

<property
name="user_id"
type="java.lang.Integer"
column="user_id"
not-null="true"
/>


</class>
</hibernate-mapping>
=======

Afterwards i try to generate java code from the .hbm.xml file with "net.sf.hibernate.tool.hbm2java.CodeGenerator", but this gives me a:

=======
java.lang.NullPointerException
at net.sf.hibernate.tool.hbm2java.BasicRenderer.makeSupportField(BasicRenderer.java:509)
at net.sf.hibernate.tool.hbm2java.BasicRenderer.render(BasicRenderer.java:111)
at net.sf.hibernate.tool.hbm2java.Generator.write(Generator.java:113)
at net.sf.hibernate.tool.hbm2java.Generator.writeRecur(Generator.java:92)
at net.sf.hibernate.tool.hbm2java.Generator.generate(Generator.java:81)
at net.sf.hibernate.tool.hbm2java.CodeGenerator.main(CodeGenerator.java:116)
=======

I suspect the problem lies in User.hbm.xml, cause the java code of Message.hbm.xml gets generated well.

When i remove:
=======
<set role="messages" table="messages">
<key column="user_id"/>
<one-to-many class="Message"/>
</set>
=======
User.hbm.xml compiles fine.

I looked throught the code for a long time, but can't see what i'm doing wrong. Anybody got a idea?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 9:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You need to give the full class name including package in your one-to-many Element I think.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 12:38 pm 
Newbie

Joined: Tue Aug 26, 2003 5:09 pm
Posts: 13
gloeglm wrote:
You need to give the full class name including package in your one-to-many Element I think.


Thanks for the reply. I tryed to replace the "Message" with "users.Message", but i still got the same error:

<set role="messages" table="messages">
<key column="user_id"/>
<one-to-many class="users.Message"/>
</set>

I'm feeling a little stupid here, cause i can't seem to find where the error comes from ;)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 12:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There is no role attribute in set, it is called name


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 11, 2004 1:44 pm 
Newbie

Joined: Tue Aug 26, 2003 5:09 pm
Posts: 13
gloeglm wrote:
There is no role attribute in set, it is called name


That did indeed fix it, thanks! It's a bit of a shame the article which mentioned "role" is not correctly written (or maybe just out-dated).


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