-->
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: Want to avoid duplicate values for perticular column
PostPosted: Wed Sep 10, 2008 5:35 am 
Newbie

Joined: Fri May 02, 2008 1:25 am
Posts: 7
How can I mapp the property when I want to avoid the duplication of perticular property which is not primary key of the data base.

For example I have one pojo class called LoginPojo

it has following fields

Integer userId
String userName
String userRole
String userPassword

The primary key of the login table is USER_ID which is mapped with the userId field. But I want the userName should not duplicate means two user can't have the same userName.

Is there any way to avoid this at the time of mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2008 9:49 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
ooops....


Last edited by Cameron McKenzie on Wed Sep 10, 2008 3:24 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2008 9:49 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Could you not just put a unique constraint on the database?

The column annotation provides some attributes you might find handy:

Code:
@Column(
  name="columnName";
    boolean unique() default false;
      boolean nullable() default true;
        boolean insertable() default true;
          boolean updatable() default true;
  String columnDefinition() default "";
    String table() default "";
       int length() default 255;
          int precision() default 0;
            int scale() default 0;
)



or

<property .... unique="true" />

Tutorial on Mapping Columns with Hibernate3

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.