-->
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.  [ 10 posts ] 
Author Message
 Post subject: Question about Hibernate Mapping Files
PostPosted: Tue Nov 10, 2009 2:28 am 
Newbie

Joined: Tue Nov 10, 2009 2:24 am
Posts: 5
Hello everyone,

i have a small question about the hibernate mapping files.

Does it make sense to set the length attribute on the property element when the type is "integer"???
I thought that the length attribute is only necessary on strings???
When do i use the "precision" and "scale" attributes?

thanks in advance

best regards

maze


Top
 Profile  
 
 Post subject: Re: Question about Hibernate Mapping Files
PostPosted: Tue Nov 10, 2009 5:26 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
On numbers you can define how exact these number should be. For example an int with length 1 can only store values not having more than one digit. So if you want to tune your database in matters of the size of your data, you should always set an appropriate length.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Question about Hibernate Mapping Files
PostPosted: Tue Nov 10, 2009 5:55 am 
Newbie

Joined: Tue Nov 10, 2009 2:24 am
Posts: 5
thanks for your reply,

i thought that precision is the number of digits that i can store in the database. What is the difference between "precision" and "length" on integer?
And what exactly is scale for?

best regards

maze


Top
 Profile  
 
 Post subject: Re: Question about Hibernate Mapping Files
PostPosted: Tue Nov 10, 2009 6:24 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
on integer you should use precision, on strings you use length.

Length on numbers is the number of bytes, which is used to store these numbers.
Hereis a good explanation.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Question about Hibernate Mapping Files
PostPosted: Tue Nov 10, 2009 6:44 am 
Newbie

Joined: Tue Nov 10, 2009 2:24 am
Posts: 5
thanks,

so this description fits to the types that are used in hibernate?

best regards

maze


Top
 Profile  
 
 Post subject: Re: Question about Hibernate Mapping Files
PostPosted: Tue Nov 10, 2009 6:53 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
I guess so. But I think it's specific to how a DB handles length constraints on decimal columns.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Question about Hibernate Mapping Files
PostPosted: Tue Nov 10, 2009 9:12 am 
Newbie

Joined: Tue Nov 10, 2009 2:24 am
Posts: 5
well, i just tested some map files and i got the result that the mapping constraints are completely ignored.

I have an integer column with a precision of 19 digits, specified in the database.
Then i have set the precision to 4 in the map file. Result: I was able to pass the 19 digits in that column without any error/warning.
After that i have set the length to 4 for this column in the mapping file. Result: Again i was able to pass the 19 digits through.

What exactly should happen when i fail the mapping constraint?

best regards

maze


Top
 Profile  
 
 Post subject: Re: Question about Hibernate Mapping Files
PostPosted: Wed Nov 11, 2009 4:57 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Well, if the column already exists in the database, hibernate will not change it's length. These attributes are passed to the db when hibernate generates the schema, they are not validated by hibernate when passing entities to the db.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Question about Hibernate Mapping Files
PostPosted: Wed Nov 11, 2009 9:15 am 
Newbie

Joined: Tue Nov 10, 2009 2:24 am
Posts: 5
mmerder wrote:
Well, if the column already exists in the database, hibernate will not change it's length. These attributes are passed to the db when hibernate generates the schema, they are not validated by hibernate when passing entities to the db.


Thanks for that, now all this makes much more sense to me :-)
I just thought that my mapping files are completely ignored.

best regards

maze


Top
 Profile  
 
 Post subject: Re: Question about Hibernate Mapping Files
PostPosted: Wed Nov 11, 2009 11:39 am 
Newbie

Joined: Wed Nov 11, 2009 10:58 am
Posts: 3
Sorry posted in the wrong section :-)


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