-->
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.  [ 3 posts ] 
Author Message
 Post subject: Maximum Length of a mapped varchar/String
PostPosted: Tue Jan 31, 2006 10:45 am 
Newbie

Joined: Fri May 27, 2005 6:16 am
Posts: 14
Hi,

I have mapped a varchar (in mysql) to a String, and set the length=** value in the mapping.

<property
name="Comment"
column="COMMENT"
type="string"
not-null="false"
length="200"
/>

I would like to check at runtime if the length of the String is not bigger then the length stated in the mapping. I looked into ClassMetaData and StringType, but could not find any references to the maximum length of a StringType. Is there any way to look this up?

Thanks a lot,
Leen Toelen


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 2:46 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Code:
       Iterator columns = Configuration.getClassMapping("your persistent class").getTable().getColumnIterator();
       for(;columns.hasNext();)
       {
              Column thisColumn = (Column) columns.next();
              if ("COMMENT".equals(thisColumn.getName()))
              {
                    length =  thisColumn.getLength();
              }
       }




Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 5:26 am 
Newbie

Joined: Fri May 27, 2005 6:16 am
Posts: 14
Great, I just have to save the Configuration for my session right now, but this method works like a charm.

Thanks a lot!
Leen


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