-->
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.  [ 9 posts ] 
Author Message
 Post subject: Best hibernate type to use, to map to a db char field > 1
PostPosted: Mon Jun 16, 2008 4:58 am 
Newbie

Joined: Mon Jun 16, 2008 3:31 am
Posts: 5
Hi,

Does anyone know the best hibernate type to use when mapping from a Java String to a db charater field, larger than 1 in length, in the hbm file.

We have been using <column name="code" sql-type="char(3)"/>
up to now but would prefer to use a hibernate type field instead.

i.e. <property name="code" type="?"

Thanks,
Nick..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 16, 2008 12:05 pm 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Hi Nick,
you are overiding the default mapping of Hibernate type to SQL datatype.

If you have a char more then 1 character length and you do not want to override the Hibernate mapping
then use type="string"

<column name="code" type="string"/>

or


<column name="code" /> in case the java type of the code is java.lang.String

I may have missed the point; please let me know about your thoughts

Thanks

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 3:36 am 
Newbie

Joined: Mon Jun 16, 2008 3:31 am
Posts: 5
Hi Alan,

Thanks for your answer. I wasn't sure whether it was string or there was another hibernate type to use. I know there is a charater type, but this is just for char 1.
Do you know why it would be a good idea to use sql-type? It looks like there are enough hibernate types to cover most instances?

Thanks,
Nick..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 4:29 am 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Nick,
Yes hibernate types coverse most SQL type.

Quote:
Do you know why it would be a good idea to use sql-type?

Well, it depends on you database design and requirements.
Sometimes you need char(3) and not varchar(3) so you overide the hibernate definition type for string by
saying

<column name="code" sql-type="char(3)"/>

instead of

<column name="code" type="string" length="3" />

since you are aware that the variable will be of a constant lenght of 3 and not a variable of max length of 3. Char(3) is more optimized for speed and Varchar(3) is more optimized for storage.


or if your database provider uses a datatype called currency and you do not want to use hibernate currency type which maps to VARCHAR

I do not think there are fix rules but rather a design related approach.

Cheers

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 4:54 am 
Newbie

Joined: Mon Jun 16, 2008 3:31 am
Posts: 5
Hi Alan,

I have a char(3) field. So for performance wise do you recommend I use a sql-type=char(3) rather than using a hibernate type of string? I was under the impression that it was better to use the hibernate types and their performance was good?

Nick..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 5:21 am 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Nick,
I am trying to say if you know that char(3) is needed and not varchar(3) then for the database which tries to retrieve the value or insert it, it is more optimized (constant better then variable). Now hibernate execute the query to make the insertion to the database so the datbase does the job to persist the data. I am not sure if Hibernate does more work when it overrides the default mapping definition.


Cheers

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 5:29 am 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Nick,
I am trying to say if you know that char(3) is needed and not varchar(3) then for the database which tries to retrieve the value or insert it, it is more optimized (constant better then variable). Now hibernate execute the query to make the insertion to the database so the datbase does the job to persist the data. I am not sure if Hibernate does more work when it overrides the default mapping definition.


Cheers

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 5:30 am 
Beginner
Beginner

Joined: Tue Dec 12, 2006 6:43 am
Posts: 32
Location: London
Nick,
I am trying to say if you know that char(3) is needed and not varchar(3) then for the database which tries to retrieve the value or insert it, it is more optimized (constant better then variable). Now hibernate execute the query to make the insertion to the database so the datbase does the job to persist the data. I am not sure if Hibernate does more work when it overrides the default mapping definition.


Cheers

_________________
Alan Mehio
London
UK


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 3:24 am 
Newbie

Joined: Mon Jun 16, 2008 3:31 am
Posts: 5
Yeah I guess, thats what I really need to find out. Why use sql-type. What advantage does this give. Why use it. Does it increase or hinder performance.


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