-->
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: Mapping: How to restrict values for a column
PostPosted: Tue Feb 20, 2007 1:18 pm 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
Hi. I am new to Hibernate and I would like to know how I can restrict the values for a column?

One attribute in my class should only contain four types of values.

Thx

EDIT: It would be great if I could map a String from the Object to an Integer in the DB (1 -> HU, 2 -> AU, ...) and vice versa


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 4:38 pm 
Regular
Regular

Joined: Mon May 22, 2006 2:30 pm
Posts: 74
Restricting the values for a column is done at the database level. Keep in mind Hibernate is an OR-mapping tool, not a database. In DB2 these are called "check constraints", and are added via DDL when the tables are created. For example, the following restricts a YES_NO_INDICATOR column to either a 'Y' or and 'N'

ALTER TABLE MY_TABLE ADD CONSTRAINT CK1
CHECK (YES_NO_INDICATOR IN ('N', 'Y'))

This is how you want to do that. Otherwise, code the check in your business logic.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 5:14 pm 
Beginner
Beginner

Joined: Sat Feb 10, 2007 12:18 pm
Posts: 23
Thx a lot.

In my case Hibernate is creating my database and I thought it might be possible to add a constraint in the mapping


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.