-->
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.  [ 4 posts ] 
Author Message
 Post subject: can we override the hibernate validation annotation?
PostPosted: Fri Jul 18, 2008 5:53 am 
Newbie

Joined: Thu Mar 30, 2006 8:18 am
Posts: 3
Hello all,

I have used Hibernate 3 with annotation for many years. I knew we can override the column attribute by using the @AttributeOverride. Now I am trying to integrate hibernate validator into our system and I get a problem: how to override the validation annotation? I have googled and found nothing, so I post here and hope someone can give me a hand. Thanks.

simple to descript it, I have two domain classes, a base one and a concrete one.

The base one called CodeBean, which contains one one property code. The code looks like (the code about the id is not relevant and ingored here):

Code:
@MappedSuperclass
public abstract class CodeBean {

   public static final String PROPERTYNAME_CODE = "code";

   private String code;
   

   public CodeBean()
   }

   // some code for generated id

   @NotEmpty
   public String getCode() {
      return code;
   }

   public void setCode(String code) {
      firePropertyChange(PROPERTYNAME_CODE, this.code, this.code = code);

   }
}


The @NotEmpty is used here for validating the code.

The concrete domain class called Country whose code length must be 2. For example "US", "DE". Now I get the Problem, where should I put the annotation @length?

First I have tried override the getCode() method like this:

Code:
@Entity
public class Country extends CodeBean {

   @Length(min = 2, max = 2, message = "The code length must be 2")
   @Override
   public String getCode() {
      return super.getCode();
   }

        // some other code

}


But in this way, I got mapping exception from the hibernate - "Caused by: org.hibernate.MappingException: Duplicate property mapping of code found...... ", when the code was compiled. That is because, with using annotation, we cannot override the property. We can only use the @AttributeOverride for overriding the column attribute of the property.

My question:

1. Have I understood the property override rule of the entity class by using the Hibernate annotation correctly? maybe there is a way to override the property using annotation?
2. Could we override the validation annotation just like the @AttributeOverride does?

thanks for reply.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 22, 2008 7:49 am 
Newbie

Joined: Thu Mar 30, 2006 8:18 am
Posts: 3
Anyone gives me a hand? Thanks.


Top
 Profile  
 
 Post subject: same problem
PostPosted: Tue Jan 20, 2009 5:22 am 
Newbie

Joined: Tue Jan 20, 2009 5:16 am
Posts: 1
Hi,

I have a similar problem using xml mapping. Have anybody found a solution yet?
Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 01, 2009 8:44 am 
Newbie

Joined: Thu Nov 06, 2008 10:42 am
Posts: 5
Me too Stuck, I could do it in JPA, but hibernate syntax not known to me
Please help


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