-->
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.  [ 10 posts ] 
Author Message
 Post subject: Feedback implementing the early-draft-spec
PostPosted: Fri Apr 04, 2008 4:52 am 
Newbie

Joined: Thu Apr 03, 2008 4:27 am
Posts: 10
Let me summarize the questions and problems we had while implementing JSR303 based on the early-darft spec. I try so list the points as short as I can with references to the chapters in the spec:

* chapter 2.1:
In some code examples, @ValidatorClass is used instead of @ConstraintValidator => typo?

* Some APIs seem quite annotation-centric
Code:
chapter 5.2: ElementDescriptor.getElementType(),
chapter 5.3: ConstraintDescriptor.getAnnotation()
chapter 2.3: Constraint.initialize(Annotation)

==> what to do when constraintdescription originates from a xml file / is not based on annotations?

* chapter 5.2: Is ElementDescriptor.getElementType() ambiguous? Isn't this rather an access-strategy per constraint than per property?
Code:
class A { @NotEmpty protected String name; }
class B extends A { @Length(max = 30) public String getName() { return name; } }

validator.getConstraintsForProperty(“name”).getElementType() => FIELD or METHOD? (@NotEmpty: FIELD, @Length: METHOD)

* chapter 3.1.2: Do you plan to explain whether or not annotation of setter-methods is supported (access strategy would be unclear)?

* chapter 3.1.2: How is the access-strategy for annotated overwritten methods:

Code:
class A {
@NotEmpty protected String getName() { return “dummy”; }
}
class B extends A {
@NotEmpty public String getName() { return “”; }
}


==> is method A#getName() called? I don't think so.

* 3.5 validation routine: Is it really neccessary to specify that field level validations are executed BEFORE property level validations or should this be an implementation detail instead?
Because: Sequence can be defined with groups/groupsequences. In case of InvalidConstraints found, validation will not stop until the group is completly validated anyway.

* chapter 3.4: I had problems understanding the required behaviour for groupSequence handling:
InvalidConstraint.groups: String instead of String[] to contain the group, where the invalidconstraint has occurred?

* chapter 4.1.1: Validator.validateProperty() + Validator.validateValue(propertyName,value,groups...)
can propertyName contain a propertyPath (with dot-notation)?

* chapter 3.1.3: How will the @Valid annotation determine the target type , especially in case of to-many relationships? (Invoke getClass() on each instance in the collection? Using reflection on the generic collection type can be a problem when generic type is Object or some interface type.) I would suggest to add an optional attribute like “hint”/”id” or “targetClass” to the @Valid annotation. That would open up the possibility to have a different validation per association role:
Code:
class User {
@Valid(hint=”HomeContact”) private Contact home;
@Valid(hint=”OfficeContact”) private Contact office;
}


Best regards
Roman


Top
 Profile  
 
 Post subject: Re: Feedback implementing the early-draft-spec
PostPosted: Mon Apr 07, 2008 4:25 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
roman.stumm wrote:
Let me summarize the questions and problems we had while implementing JSR303 based on the early-darft spec. I try so list the points as short as I can with references to the chapters in the spec:

* chapter 2.1:
In some code examples, @ValidatorClass is used instead of @ConstraintValidator => typo?

Yep, typo due to a last minute change.

Quote:
* Some APIs seem quite annotation-centric
Code:
chapter 5.2: ElementDescriptor.getElementType(),
chapter 5.3: ConstraintDescriptor.getAnnotation()
chapter 2.3: Constraint.initialize(Annotation)

==> what to do when constraintdescription originates from a xml file / is not based on annotations?

Generate the annotation. Annotations are the meta model today.

Quote:
* chapter 5.2: Is ElementDescriptor.getElementType() ambiguous? Isn't this rather an access-strategy per constraint than per property?
Code:
class A { @NotEmpty protected String name; }
class B extends A { @Length(max = 30) public String getName() { return name; } }

validator.getConstraintsForProperty(“name”).getElementType() => FIELD or METHOD? (@NotEmpty: FIELD, @Length: METHOD)


I agree, I noticed that. AFAIR it has some implications, but we need to address that.

Quote:
* chapter 3.1.2: Do you plan to explain whether or not annotation of setter-methods is supported (access strategy would be unclear)?


setter annotation are not supported, does it read differently?

Quote:
* chapter 3.1.2: How is the access-strategy for annotated overwritten methods:

Code:
class A {
@NotEmpty protected String getName() { return “dummy”; }
}
class B extends A {
@NotEmpty public String getName() { return “”; }
}


==> is method A#getName() called? I don't think so.

A#getName() is not called as it would require some bytecode manipulation, but constraints on A#getName() will be called. In your example @NotEmpty will be checked twice
This is explained in 3.3.

Quote:
* 3.5 validation routine: Is it really neccessary to specify that field level validations are executed BEFORE property level validations or should this be an implementation detail instead?
Because: Sequence can be defined with groups/groupsequences. In case of InvalidConstraints found, validation will not stop until the group is completly validated anyway.

Why do you think the wording in 3.5 implies an order between field and method? I does not.

Quote:
* chapter 3.4: I had problems understanding the required behaviour for groupSequence handling:
InvalidConstraint.groups: String instead of String[] to contain the group, where the invalidconstraint has occurred?

This is not very well defined. The thing is I am not sure we can define that property (especially because of the group sequence expendability). We are looking for feedback on the usefulness of this feature.

Quote:
* chapter 4.1.1: Validator.validateProperty() + Validator.validateValue(propertyName,value,groups...)
can propertyName contain a propertyPath (with dot-notation)?

Do you think it is useful?

Quote:
* chapter 3.1.3: How will the @Valid annotation determine the target type , especially in case of to-many relationships? (Invoke getClass() on each instance in the collection? Using reflection on the generic collection type can be a problem when generic type is Object or some interface type.) I would suggest to add an optional attribute like “hint”/”id” or “targetClass” to the @Valid annotation. That would open up the possibility to have a different validation per association role:
Code:
class User {
@Valid(hint=”HomeContact”) private Contact home;
@Valid(hint=”OfficeContact”) private Contact office;
}



No this is a runtime resolution. We probably need to be be more clear about that.

Thanks for your feedback

_________________
Emmanuel


Top
 Profile  
 
 Post subject: to annotate or not to annotate...
PostPosted: Tue Apr 08, 2008 3:01 am 
Newbie

Joined: Thu Apr 03, 2008 4:27 am
Posts: 10
Hello Emmanuel,

thanks for your reply that clarified most of the issues I mentioned (and helped us to update our JSR303 implementation).

Let me answer to two points from your reply:
Quote:
Generate the annotation. Annotations are the meta model today.

I agree, but in this case it means: code generation, doesn't it?
The point is (similar to post "Non-intrusive constraint declaration"), that annotations are bound 1:1 to a type while the flexible validation solution we are using contains the feature to have different validation definitions per class without modification of the source. Basic validations (e.g. based on constraints of the database) can be expressed by annotations, others can be added like decorators on higher application layers and may differ when customizing the application for different clients (also during runtime). They are currently based on XML. How could those constraints appear in the metadata request APIs?

Quote:
Validator.validateProperty() + Validator.validateValue(propertyName,value,groups...)
can propertyName contain a propertyPath (with dot-notation)?
==> Do you think it is useful?

Maybe the API becomes more "symmetric" when you can re-validate with the beanClass/rootBean/value/propertyPath values from the InvalidConstraint. Why should the API offer the ability to validate some single properties while others cannot be validated separately just because they are inside a child object? But this is of low priority in my opinion.


Best regards
Roman


Top
 Profile  
 
 Post subject: Re: to annotate or not to annotate...
PostPosted: Thu Apr 10, 2008 6:17 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
roman.stumm wrote:
Let me answer to two points from your reply:
Quote:
Generate the annotation. Annotations are the meta model today.

I agree, but in this case it means: code generation, doesn't it?

Not really, an annotation is an interface, you can create a proxy implementing annotations

Quote:
The point is (similar to post "Non-intrusive constraint declaration"), that annotations are bound 1:1 to a type while the flexible validation solution we are using contains the feature to have different validation definitions per class without modification of the source. Basic validations (e.g. based on constraints of the database) can be expressed by annotations, others can be added like decorators on higher application layers and may differ when customizing the application for different clients (also during runtime). They are currently based on XML. How could those constraints appear in the metadata request APIs?

Let me know what you think of
http://in.relation.to/Bloggers/BeanVali ... Validation

Quote:
Quote:
Validator.validateProperty() + Validator.validateValue(propertyName,value,groups...)
can propertyName contain a propertyPath (with dot-notation)?
==> Do you think it is useful?

Maybe the API becomes more "symmetric" when you can re-validate with the beanClass/rootBean/value/propertyPath values from the InvalidConstraint. Why should the API offer the ability to validate some single properties while others cannot be validated separately just because they are inside a child object? But this is of low priority in my opinion.

The problem is that '.something' means both getter and field.
We have the problem already when limited to one level though

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Role-Based Validation
PostPosted: Wed Apr 16, 2008 10:06 am 
Newbie

Joined: Thu Apr 03, 2008 4:27 am
Posts: 10
Quote:
an annotation is an interface, you can create a proxy implementing annotations


Yes, OK.

Quote:


Ok, I see, that the concept of groups can solve most of the issues.

I am curious about how the runtime resolution of associated beans will be described in the final spec..


Top
 Profile  
 
 Post subject: Re: Role-Based Validation
PostPosted: Wed Apr 23, 2008 8:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
roman.stumm wrote:
I am curious about how the runtime resolution of associated beans will be described in the final spec..


What do you mean?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: runtime resolution of objects in relationships
PostPosted: Thu Apr 24, 2008 4:06 am 
Newbie

Joined: Thu Apr 03, 2008 4:27 am
Posts: 10
Quote:
this is a runtime resolution. We probably need to be be more clear about that.

What I meant by "I am cursious about the specification of runtime resolution" is, that on one hand, you need a class to construct a Validator:
Code:
new ClassValidator(Person.class);

but on the other hand, an object in the relationship will probably be validated by its concrete runtime type.
So what happens if I validate a subclass of Person with a validator created for Person.class? Does it validate the Person-attributes only?
Will validation work properly for associated objects, then the getter's or field's type is just java.lang.Object (or some Interface)? To validate a to-many relationship, each instance's type must be determined (sending each.getClass(), even it is a dynamic proxy) and a proper validator must be created.
Why is a Class-object required to create the initial ClassValidator, when the framework needs to be more dynamic for validation of associated objects?
I just wait for the next release of the spec and see if it clarifies this a little.

Thanks for your attention. Regards, Roman


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 24, 2008 10:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Ah yes that's a good point.
The association must have dynamic determination.
The API is cleaner when a type is used but I am not sure it is that useful considering what you said. I've added a note.
So you would trop the generic altogether?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 25, 2008 6:21 am 
Newbie

Joined: Thu Apr 03, 2008 4:27 am
Posts: 10
emmanuel wrote:
So you would drop the generic altogether?


As far as I understand the intention of the draft-spec, the generic in interface Validator<T> is a good thing for a clean API. But the passage in chapter 4.1:

Quote:
Besides implementing the Validator<T> API, the Bean Validation provider implementation of Validator<T> must have a constructor Validator(Class<T>).


should be dropped, because it implies that the constructor argument Class<T> is used to determine the initialization of the Validator (but as we already discussed the Validator must be more dynamic anyway). So the spec needs not mention restrictions on the constructor - a zero-arg constructor would be ok, too and the interface Validator<T> can keep the generic.

But caution: when the Validator is constructed without a class-argument, the metadata-request-API must also change, because methods like "hasConstraints", "getBeanConstraints", "getConstraintsForProperty", "getValidatedProperties", need a parameter (Class) then.

With best regards
Roman


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 6:31 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes, my main concern is that without generics, you cannot access the metadata APIs, so we might still keep the generic version around.

_________________
Emmanuel


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