Hibernate Books

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: UserType - predefined coulmn length
PostPosted: Wed Feb 15, 2012 6:26 am 
Newbie

Joined: Fri Jan 20, 2012 9:44 am
Posts: 5
Hello,...

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)));
}


Could anyone help me with that pls?
I'm open to any idea...

Thanks a lot,
Robbie


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.