-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Mapping Types - be precise
PostPosted: Fri Jul 07, 2006 6:23 am 
Newbie

Joined: Wed Jun 28, 2006 1:03 am
Posts: 14
When I have this in my mapping file (hbm.xml):

Code:
    <id name="id" column="ID">
        <generator class="native"/>
    </id>


the generated SQL is :

Code:
    `ID` int(11) NOT NULL auto_increment


But I want SMALLINT and not int(11)

How do I specifically specify the SQL types that I want ? Hibernate generates "approximate" datatypes for both the SQL and Java sides which, to me, is quite annoying. I think I know best which datatype to use ... for example, I want a field in my Java class to be Integer and map it to SMALLINT in the DB.

Also, I tried finding on the net a "mapping table" ... something like this:
Java DataType - Hibernate Mapping Type - MySQL datatype
String - string - varchar
etc etc
...

But, surprisingly I could not find any. Those that I found were very vague ... they go something like :


Code:
    integer, long, short, float, double, character, byte, boolean, yes_no, true_false
    Type mappings from Java primitives or wrapper classes to appropriate (vendor-specific) SQL column
    types. boolean, yes_no and true_false are all alternative encodings for a Java boolean or
    java.lang.Boolean.


I need a more "precise" table..showing which exact type map to which.


DB : MySQL

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 07, 2006 8:06 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

you might want to try something like this:
Code:
<id name="id">
   <column name="ID" sql-type="INT"/>
   <generator class="native"/>
</id>


I think that way you should be able to specify any sql-type your database supports.


Top
 Profile  
 
 Post subject: Unsigned ID
PostPosted: Fri Jul 07, 2006 9:00 am 
Newbie

Joined: Wed Jun 28, 2006 1:03 am
Posts: 14
piet.t, thanks for suggesting that solution. It does give me SMALLINT which I wanted

But with
Code:
        <id name="id">
           <column name="ID" sql-type="SMALLINT"/>
            <generator class="native"/>
        </id>


I get
Code:
 
`ID` smallint(6) NOT NULL auto_increment,


It is not unsigned. I need the SMALLINT to be unsigned. Hibernate has facility for that ?

Thanks
[/code]


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