-->
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.  [ 5 posts ] 
Author Message
 Post subject: SchemaExport not honoring length for character columns
PostPosted: Mon Jan 03, 2005 5:01 pm 
Newbie

Joined: Sun Jan 02, 2005 6:30 pm
Posts: 2
Hibernate version:
2.1
Mapping documents:
<property name="abbreviation" type="string">
<meta attribute="field-description">
A 2 digit abbreviation of the state or province's name.
</meta>
<meta attribute="scope-get">public</meta>
<meta attribute="scope-set">protected</meta>
<column
length="2"
name="abbreviation"
not-null="true"
sql-type="char"
/>
</property>
Name and version of the database you are using:
PostgreSQL 7.4.2
The generated SQL (show_sql=true):
abbreviation char not null,

The SchemaExport utility seems to ignore the length attribute of the column element if the sql-type attribute is "char".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 03, 2005 6:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The char type (to me) implies one character so it appears reasonable to me. Change the type to varchar which is more appropriate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 03, 2005 7:57 pm 
Newbie

Joined: Sun Jan 02, 2005 6:30 pm
Posts: 2
Historically, I've always used char(len) rather than varchar(len) in cases where I *know* the values will be a certain length exactly, such as SHA-1 hashed passwords. To me it makes sense. My argument is not strengthened by the SQL standard, since it will happily take a character field shorter than 32 characters and store it in a char(32) field after padding it.

According to the docs on postgresql, there is no speed difference between char(len) and varchar(len). I dunno if this is true for all db platforms and it may give me trouble with index speeds if not. I plan on making this application run on many db platforms, and liked hibernate because it can help me in that endever.

I guess I will switch to using varchar(len) and tweaking the exported SQL by hand where necessary.

Thank your for your consideration.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 04, 2005 3:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
sql-type="char(xx)" should do what you want. (if i remember correctly)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 04, 2005 8:32 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If a platform accepts both char(x) and varchar(x) they will be the same fixed length field implementation below the covers. Either is fine (and yes sql-type="char(x)" [where x is a length int]) will work) but there is the sematics that bother me just a little.


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