-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to limit String length
PostPosted: Thu Nov 02, 2006 10:21 am 
Newbie

Joined: Tue May 23, 2006 3:41 am
Posts: 6
I need to create restriction on String field.
In an ideal situation - if inserted data length exeed permited length the program should create warning, and cut to permited lenght if user insist.
I try to use length in <property> element, in mapping file, like

Code:
      <property name="regCode" type="string" column="reg_code" length="10"/>

it not helps. In db column reg_code got 40 varchar and if I put in program 12 chars - all of them in database.
The only possibility I found - to put into bean file
Code:
   public void setRegCode(String regCode) {
      this.regCode = regCode.substring(0, 10);
   }

But this "method" quite stupid
db - mySQL 5.0.22


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 10:36 am 
Senior
Senior

Joined: Fri May 14, 2004 9:37 am
Posts: 122
Location: Cologne, Germany
Your database field length should also be 10 Hibernate doesn't limit the Field length to the one in the mapping file, but you can analyse the Mappings Files during runtime and do the validation there, you can also create a BeanInfo that has the Information of the POJO, this BeanInfo can validate the POJO then or even the newest Version of Hibernate 3.2 can do this validation. Look inside the Manual there should be some example how to use validation in Hibernate.

_________________
regards

Olaf

vote if it helped


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