-->
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: UserType with CHAR(4) SQL type
PostPosted: Mon Apr 24, 2006 4:45 pm 
Newbie

Joined: Thu May 05, 2005 6:27 pm
Posts: 7
I've created a new user type for which I'd like an underlying
SQL type of CHAR(4).

The UserType can define the sql type through the method
sqlTypes(). However, looks like I can only choose between
Types.CHAR and Types.VARCHAR.

Types.CHAR is of size 1, and Types.VARCHAR is of size 255.
The first option doesn't work, the second is ok, but not optimal.

Is there any "hint" I can pass to schema generation so that it
creates columns of type CHAR(4) for this user type?

Thank you
-Andrej


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 24, 2006 4:56 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
'length' attribute of the property
http://www.hibernate.org/hib_docs/v3/re ... n-property

But IMO it is better not to generate schema from hbm files.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: thank's
PostPosted: Mon Apr 24, 2006 9:07 pm 
Newbie

Joined: Thu May 05, 2005 6:27 pm
Posts: 7
I wasn't aware the length attributed applied to user types as well.
Great, thank's.


Top
 Profile  
 
 Post subject: Re: UserType with CHAR(4) SQL type
PostPosted: Wed Feb 15, 2012 10:01 am 
Newbie

Joined: Fri Jan 20, 2012 9:44 am
Posts: 5
So, does that mean, that it is impossible to get the length of column in UserType?

Because ... I'm defining my own UserType called FixedString and in nullSafeSet method I'd like to fill all string values with blanks (up to length of that column defined with annotation:
@Column(length=100, nullable=true)).

I have no problem to trim all strings in nullSafeGet method (with StringUtils.trim method):
Code:
public Object nullSafeGet(ResultSet inResultSet, String[] names, Object o) throws SQLException {
   String val = (String)Hibernate.STRING.nullSafeGet(inResultSet, names[0]);
   return StringUtils.trim(val);
}


,but I have no idea how I can get the length of current column (in my case COLUMN_LENGTH).
Code:
public void nullSafeSet(PreparedStatement inPreparedStatement, Object o, int i) throws SQLException {
   String val = (String)o;
   inPreparedStatement.setString(i, StringUtils.rightPad(val, COLUMN_LENGTH)));
}


Any idea how I can get the length (defined in by the @Column annotation) in UserType?
Thanks a lot for any help!

Rob


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.