-->
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: BIG Hibernate Validator Problem
PostPosted: Sun May 24, 2009 8:52 am 
Newbie

Joined: Sun May 24, 2009 8:50 am
Posts: 3
Hi,

I have a class Question with some fields and an one to many with FormattedTextChoice.
Code:
@Entity
@DiscriminatorValue("RBQ")
@SuppressWarnings("unused")
public class RadioBoxQuestion{
   private String request;
   ...

   @Size(min = 2, max = Question.MAXIMUM_CHOICES_PER_QUESTION)
   @OneToMany(fetch = FetchType.EAGER, cascade =  CascadeType.ALL)
   @JoinColumn(name = "RADIO_BOX_QUESTION_ID")
   @OrderBy(clause = "position ASC")
   @ForeignKey(name="CHOICES__RADIO_BOX_QUESTIONS_FK")
   public Set<FormattedTextChoice> getRadioBoxChoiceSet() {
      return radioBoxChoiceSet;
   }
   ...
   @AssertTrue
   public boolean validateChoicePositions() {
       System.out.println("RadioBoxQuestion.validateChoicePositions(!!!!!!!)");
      return Utils.validateElementsPosition(radioBoxChoiceSet);
      
   }
}


The problem is that whenever I try to update any of FormattedTextChoice objects and I do NOT modify the Question request field, the method annotated with @asserttrue (validateChoicePositions) is ignored!!!

So a code like:
...
myFormattedTextChoice = ...;
myFormattedTextChoice.setPosition(9999);
questioningDao.update(question);

will result in corrupted data for me.


But, if I modify also the request field, then will work as expected, and will execute the validateChoicePositions method.

Any clues?


Top
 Profile  
 
 Post subject: Re: BIG Hibernate Validator Problem
PostPosted: Mon May 25, 2009 8:32 am 
Newbie

Joined: Sun May 24, 2009 8:50 am
Posts: 3
Any clues?


Top
 Profile  
 
 Post subject: Re: BIG Hibernate Validator Problem
PostPosted: Thu May 28, 2009 6:24 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Can you be a little bit more specific? What version of Hibernate Core / Validator are you using? There is a huge difference in the codebase. From 4.x onwards Validator is based on Bean Validation.

Not exactly knowing what you are actually asking for, but why should RadioBoxQuestion be validated again, even though it is unchanged? The validation occurs as part of a update even, but since RadioBoxQuestion hasn't changed there would be not such event.

--Hardy


Top
 Profile  
 
 Post subject: Re: BIG Hibernate Validator Problem
PostPosted: Thu May 28, 2009 6:55 am 
Newbie

Joined: Sun May 24, 2009 8:50 am
Posts: 3
Hi,

What exactly want:

A question has some ordered choices and each choice has a unique position inside that question.
So a user can, in GUI, move a choice up, or down. On submit, I call updateQuestion (merge) and it will update all choices because of the cascade. Indeed it will update the choice positions, but my validate method is not called, and it is possible to have corrupted positions.

But in case that the user, also update the request field, which is in the same form, all will work ok and my method is called.


I am using :
Hibernate 3.3.1.GA
Hibernate Validator 3.1.0.GA
Hibernate EntityManager 3.3.2.GA
Hibernate Annotations 3.4.0.CR1


Thank you in advance.


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.