-->
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: hibernate.id incorrect generation? (Newbie)
PostPosted: Mon Dec 06, 2004 4:55 pm 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
Hi,

I'm using hibernate 2.1, and while I have used xdoclet for other things, this is the first time with hibernate. It seems that my generated mapping file is not generating the ID correctly. Here's the POJO:

/**
* @hibernate.class table = "CAT"
*/
public class Cat {

private String id = "";
private String name = "";
private String sex = "";
private float weight = 0.0f;

public Cat() {
}

/**
* @hibernate.id generator-class = "uuid.hex" column = "CAT_ID"
*/
public String getId() {
return id;
}
...

Here's what it generates:

<hibernate-mapping>
<class name="entities.Cat" table="CAT">
<id name="id" column="CAT_ID" type="java.lang.String">
<generator class="uuid.hex"></generator>
</id>
<property name="name" type="java.lang.String" column="name" />
<property name="sex" type="java.lang.String" column="sex" />
<property name="sex" type="void" column="sex" />
<property name="weight" type="float" column="weight" />
</class>
</hibernate-mapping>


But hibernate doesn't like that (net.sf.hibernate.MappingException: Error reading resource: entities/Cat.hbm.xml). Here's the hand-coded mapping file that works:

<hibernate-mapping>
<class name="entities.Cat" table="CAT">
<id name="id" type="string" unsaved-value="null">
<column name="CAT_ID" sql-type="char(32)" not-null="true" />
<generator class="uuid.hex" />
</id>
...
</class>
</hibernate-mapping>

So, my question is, how do I get that mapping from xdoclet? Or is there something else fundamentally wrong?

Thanks,

Don


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 6:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You just have to form your XDoclet markup to produce the mapping you want. You hand crafted example has a separate column tag so you need a separate XDoclet markup line, eg, something like


Code:
/**
  * @hibernate.id generator-class="uuid.hex" unsaved-value="null"
  * @hibernate.column name="CAT_ID" sql-type="char(32)" not-null="true"
  */
public String getId() {
     return id;
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 6:58 pm 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
david wrote:
You just have to form your XDoclet markup to produce the mapping you want. You hand crafted example has a separate column tag so you need a separate XDoclet markup line, eg, something like


Code:
/**
  * @hibernate.id generator-class="uuid.hex" unsaved-value="null"
  * @hibernate.column name="CAT_ID" sql-type="char(32)" not-null="true"
  */
public String getId() {
     return id;
}


I tried that, and I get the following, which is even worse...

Code:
<class name="entities.Cat" table="CAT">
<id name="id" column="id" type="java.lang.String" unsaved-value="null">
<generator class="uuid.hex"></generator>
</id>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 7:23 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I just played around with it (not lastest version of XDoclet though) and it appears it ignores the column tag when used with the id tag. It works correctly with the property tag. This limitation should be sent to XDoclet's JIRA so it can be fixed. For now you should get a working mapping by simply using.

Code:
/**
  * @hibernate.id generator-class="uuid.hex" column="CAT_ID" unsaved-value="null"
  */


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 1:02 am 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
david wrote:
I just played around with it (not lastest version of XDoclet though) and it appears it ignores the column tag when used with the id tag. It works correctly with the property tag. This limitation should be sent to XDoclet's JIRA so it can be fixed. For now you should get a working mapping by simply using.

Code:
/**
  * @hibernate.id generator-class="uuid.hex" column="CAT_ID" unsaved-value="null"
  */


Sorry to be a pain, but the above code doesn't work. That was my first stab at it, and trying it again gives me the same mapping file that hibernate is just as unhappy with. I know that I can hand-build the correct XML, but that doesn't help my team as we are building our application. I'll try sending a JIRA to the XDoc team. Looks like it's hand-building in the mean time.

Don


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 6:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
What is the error - it should be OK. I quickly re-read the thread and I cannot see any major difference between your orginal XDoclet mapping and the hand coded one (other than the unsaved-value). You should try and see what is wrong with it - not the generator open and close tags with no contents? I cannot try it out at the moment but maybe later.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 08, 2004 11:46 pm 
Beginner
Beginner

Joined: Mon Dec 06, 2004 4:20 pm
Posts: 34
Turns out it was the DTD referring to the hibernate-mapping-1.1.dtd instead of 2.0. Changing that fixes it, but I'm wondering how to fix the xdoc generator, which I run from Eclipse.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 09, 2004 10:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Xdoclet script is fairly easy to understand. Have a look at the source. You could also create JIRA entries for the request(s) that you have.


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.