-->
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.  [ 4 posts ] 
Author Message
 Post subject: Ambigouous mapping of hibernate-type to real java type
PostPosted: Thu May 10, 2007 11:05 am 
Newbie

Joined: Thu May 10, 2007 9:39 am
Posts: 3
Location: Germany
Hibernate Tools version: 3.2.0b9

Mapping documents:
Code:
<hibernate-reverse-engineering>
<type-mapping>
   <sql-type jdbc-type="DECIMAL" hibernate-type="long" precision="12"
      not-null="true">
   </sql-type>

   <sql-type jdbc-type="DECIMAL" hibernate-type="int" precision="10"
      not-null="true">
   </sql-type>

   <sql-type jdbc-type="DECIMAL" hibernate-type="integer" precision="8"
      not-null="true">
   </sql-type>

   <sql-type jdbc-type="DECIMAL" hibernate-type="java.lang.Integer"
      precision="10" not-null="false">
   </sql-type>
</type-mapping>
<table-filter match-name=".*"/>
</hibernate-reverse-engineering>


Name and version of the database:
Oracle 9

It is absolutely not comprehensible what effect the hibernate-type as in the examples above has on code generation.
For mandatory fields (not-null=true) i had the following results:
Code:
long -> private long doUniqueIdPk;

Code:
integer -> private java.lang.Integer doUniqueIdPk;

Code:
int-> private int doUniqueIdPk;


For nullable fields:
Code:
Long -> private java.lang.Long doUniqueIdPk;

Code:
Integer -> private java.lang.Integer doUniqueIdPk;


The results for nullable fields are IMHO correct.

The results for mandatory field are weird. long produces java primitive long. That is fine, as you cannot assign null to it. But: is long the hibernate type or the java primitive?
integer produces java.lang.Integer, which is not wanted, as it is a non-nullable value. integer is obviously a hibernate type.
int produces primitive int, which is fine for a non-nullable value. int is the java primitive type.

To me there are two problems in this:
a) for hibernate-type there are two namespaces mixed together, java.lang and Hibernate. I did not find a way to qualify the values in the documentation.
b) integer should generate a java primitive int for not-null="true".

Furthermore the hibernate-type (Tools) and type (Core) attributes should be documented much better. There should be a table that clearly points out, what results in what.

So long,
Hayo


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 8:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
not-null at db-lvl does not mean that your pojo will be not-null.

e.g. for identifiers it is of course not-null at db level but at pojo level it is null until it becomes persistent.

So it it is *really* easy:

If you want primtive types then use the primitive names (e.g. int, not integer nor java.lang.Integer)

Otherwise use the hibernate/java object style names.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 4:49 am 
Newbie

Joined: Thu May 10, 2007 9:39 am
Posts: 3
Location: Germany
First of all, thanks for you answer!

Quote:
not-null at db-lvl does not mean that your pojo will be not-null.
e.g. for identifiers it is of course not-null at db level but at pojo level it is null until it becomes persistent.

I assumed it to be that way, of course only for data types that can be represented primitive types. This way you can catch invalid null assignments even before you post to the database.
The developer using hibernate has to make assumptions for the lack of documentation on this issue (at least in hibernate_tools.pdf and hibernate_reference.pdf).

Quote:
So it it is *really* easy:

Still not to me, because...

Quote:
If you want primtive types then use the primitive names (e.g. int, not integer nor java.lang.Integer)

... i do not know what hibernate-type or type long, short, byte and double is. Is it a hibernate or a primitive type?
If these are hibernate types, then integer and long behave different: long -> long, integer -> java.lang.Integer. This would be inconsistent behaviour.
If these are primitive types, then it is not possible to use these hibernate types according to the documentation.

Quote:
Otherwise use the hibernate/java object style names.

How can i use hibernate object style names? Could it be something like hibernate-type="Hibernate.LONG"? But this would be an undocumented feature.

Hayo


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 11, 2007 11:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Quote:
So it it is *really* easy:

Still not to me, because...

Quote:
If you want primtive types then use the primitive names (e.g. int, not integer nor java.lang.Integer)

... i do not know what hibernate-type or type long, short, byte and double is. Is it a hibernate or a primitive type?
[/quote]

eh - you do know java, right ? :)
sorry just kidding...so for example:

long, short, byte and double is java types hence they are not hibernate types

integer, string, yes_no, big_decimal are not java types hence they are hibernate types.

Quote:
If these are hibernate types, then integer and long behave different: long -> long, integer -> java.lang.Integer. This would be inconsistent behaviour.


It is consitent "integer" is hibernate short-hand type for "java.lang.Integer" hence they behave equal.

Quote:
If these are primitive types, then it is not possible to use these hibernate types according to the documentation.


I don't understand where it says hibernate types are not possible to use.

Quote:
Quote:
Otherwise use the hibernate/java object style names.

How can i use hibernate object style names? Could it be something like hibernate-type="Hibernate.LONG"? But this would be an undocumented feature.


just type the names, e.g. "integer", "long", "byte" etc.

_________________
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.  [ 4 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.