Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Confused about @Email
PostPosted: Mon Apr 21, 2014 8:44 am 
Newbie

Joined: Fri Nov 06, 2009 6:05 am
Posts: 12
Looking at the start page of http://beanvalidation.org/ left me puzzled. I thought @Email wasn't part of BV, neither 1.0 nor 1.1 - and indeed it isn't (pity).

I found a thread from 2009 that discussed its potential inclusion: https://forum.hibernate.org/viewtopic.php?f=26&t=993681&start=0&hilit=email

I believe the most prominent BV code sample on the official website shouldn't feature an annotation that isn't part of the spec.

_________________
my2cents @ http://www.frightanic.com/


Top
 Profile  
 
 Post subject: Re: Confused about @Email
PostPosted: Wed Apr 23, 2014 8:19 am 
Newbie

Joined: Wed Apr 23, 2014 8:09 am
Posts: 1
I'm also confused. But more about the example itself:
currently it looks like:
public void createUser(@Email email, @NotNull String name) {}
in my opinion it should be:
public void createUser(@Email String email, @NotNull String name) {}

Maybe I'm simply wrong and I don’t understand this example.


Top
 Profile  
 
 Post subject: Re: Confused about @Email
PostPosted: Thu Apr 24, 2014 4:09 pm 
Newbie

Joined: Fri Nov 06, 2009 6:05 am
Posts: 12
juerg.drollinger wrote:
in my opinion it should be:
public void createUser(@Email String email, @NotNull String name) {}


Yep, that's correct.

_________________
my2cents @ http://www.frightanic.com/


Top
 Profile  
 
 Post subject: Re: Confused about @Email
PostPosted: Mon Apr 28, 2014 9:43 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
I've fixed the example on beanvalidation.org; Thanks for the pointer!

Regarding the usage of @Email: It's one of Bean Validation's core features to allow for the implementation of custom constraints so it makes sense to show-case this in the example.

Hibernate Validator - the BV reference implementation - comes with an @Email constraint, which btw. is surprisingly hard to get right as different definitions for a valid e-mail address apply in different contexts. E.g. "bob" might be a valid e-mail address on localhost, but typically that's not what one wants when validating input representing e-mail addresses. Also allowed length for the domain and name part are not 100% clearly defined either as different RFCs apply.

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
 Post subject: Re: Confused about @Email
PostPosted: Mon Apr 28, 2014 11:52 am 
Newbie

Joined: Fri Nov 06, 2009 6:05 am
Posts: 12
Thanks for fixing the sample.

I was neither criticizing the fact that @Email is included in the sample nor that it isn't part of the spec. I fully understand why it can't be in the spec but I still wish the circumstances were such that it'd be feasible to include it...

However, I'd still appreciate if the code sample would make it very clear that @Email isn't part of BV but a Hibernate extension.

_________________
my2cents @ http://www.frightanic.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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.