-->
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.  [ 2 posts ] 
Author Message
 Post subject: Id type and hibernate property problem
PostPosted: Wed Nov 08, 2006 7:11 pm 
Regular
Regular

Joined: Wed Mar 15, 2006 1:48 pm
Posts: 91
I have an interesting finding in 3.2beta8 and MySQL 5 in hbm2hbm case in ant env.

1. If I enable hibernate.default_schema=xxx OR hibernate.default_catalog=xxx in hibernate property file to generate catalog attribute in class element of hbm file, I got return type for id as below,

<id name="id" type="int">

if I enable both hibernate.default_schema=xxx AND hibernate.default_catalog=xxx, I can't get catalog attribute any more. Generated id is like,

<id name="id" type="java.lang.Integer">

In these two cases, even I put following in rev. template file it is yet taken.

<sql-type jdbc-type="DECIMAL" precision="7" scale="0"
hibernate-type="Integer" />(or "java.lang.Integer")

So why id type is associated with catalog attribute?

2. In non-id field, similar problem occurs based on if column's field is allowed for NULL. If NULL is allowed, that field will be mapped to a wrapper class type; otherwise it will be mapped to primitive type. For example,

city smallint(4) YES (for NULL)
county smallint(3) NO (for NULL)

I got following mapping,

<property name="city" type="java.lang.Short">
<column name="city">
<comment></comment>
</column>
</property>
<property name="county" type="short">
<column name="county" not-null="true">
<comment></comment>
</column>
</property>

Why do we have such an inconsistence in hbm generation?

Generally, item 1 affects my work since hibernate needs a wrapper class type to determine if it is a new record or existing one; Item 2 doesn't since java will handle conversion between primitive type and its corresponding wrapper, but I want to know why it is inconsistent.


Top
 Profile  
 
 Post subject: Re: Id type and hibernate property problem
PostPosted: Thu Nov 09, 2006 3:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
kkus wrote:
1. If I enable hibernate.default_schema=xxx OR hibernate.default_catalog=xxx in hibernate property file to generate catalog attribute in class element of hbm file, I got return type for id as below,

<id name="id" type="int">


ok.

Quote:
if I enable both hibernate.default_schema=xxx AND hibernate.default_catalog=xxx, I can't get catalog attribute any more.


Yes, since you have told the tools which catalog should be considered the default and thus it will not include the default catalog in the output - if you had two catalogs the other one would be in the output.

Quote:
Generated id is like,

<id name="id" type="java.lang.Integer">



And what is the chosen strategy ? are they the same ?

"int" is normally chosen when the generator is assigned which means the id cannot/should not be null.

With a generator id's should be allowed to be null.

Quote:
In these two cases, even I put following in rev. template file it is yet taken.

<sql-type jdbc-type="DECIMAL" precision="7" scale="0"
hibernate-type="Integer" />(or "java.lang.Integer")



Probably because your column is not being reported as DECIMAL, 7, 0 from mysql (the most likely cause)

Quote:
So why id type is associated with catalog attribute?


You need to show the reveng.xml and more of the generated output for me to be more conclusive than the suggestions above.

Quote:
2. In non-id field, similar problem occurs based on if column's field is allowed for NULL. If NULL is allowed, that field will be mapped to a wrapper class type; otherwise it will be mapped to primitive type. For example,

city smallint(4) YES (for NULL)
county smallint(3) NO (for NULL)

I got following mapping,

<property name="city" type="java.lang.Short">
<column name="city">
<comment></comment>
</column>
</property>
<property name="county" type="short">
<column name="county" not-null="true">
<comment></comment>
</column>
</property>

Why do we have such an inconsistence in hbm generation?


Sorry, but what is the problem ? if not-null="true" then the primitive version is chosen because it cannot be null.

If you want to override it you need to have a type-mapping that matches and i think you don't have that.

Quote:
Generally, item 1 affects my work since hibernate needs a wrapper class type to determine if it is a new record or existing one;


Hibernate 3 does not need such thing.

Quote:
Item 2 doesn't since java will handle conversion between primitive type and its corresponding wrapper, but I want to know why it is inconsistent.


I don't think its inconsistent, it follows the not-null definition by default.

_________________
Max
Don't forget to rate


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