-->
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.  [ 7 posts ] 
Author Message
 Post subject: Predefined groups and JPA integration
PostPosted: Fri Apr 18, 2008 1:00 pm 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
The groups feature of JSR-303 is a really great idea, and I think that useful for a lot of cases.
But, there is a typical case in business applications that is a validation to be enforced on creation but not on update. In fact, OpenXava validation annotations have a onlyOnCreate attribute for this case, look at:
http://www.gestion400.com/OpenXavaDoc/a ... dator.html
http://www.gestion400.com/OpenXavaDoc/a ... dator.html

My proposal is to add standard (or predefined) groups to JSR-303 that can be understood by JPA implementations, in this way;

Code:
@ForbiddenPrice(groups=JPAGroups.ON_PERSIST)
private BigDecimal price;


In this case ForbiddenPrice is only enforced on persist, not on update.
With these standard groups we can develop more portable applications.

What do you think ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 23, 2008 8:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Those group definitions should be part of JPA 2 rather than JSR 303. I noted the point.
Can you give me a use case though

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 07, 2008 12:59 pm 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
emmanuel wrote:
Those group definitions should be part of JPA 2 rather than JSR 303. I noted the point.

Thanks

Quote:
Can you give me a use case though


The next code is from an existing OpenXava application:
Code:
@Entity
@EntityValidator(value=ValidadorNoDuplicarHojaPadronal.class,
      onlyOnCreate=true
)
public class HojaPadronal {

This using Bean validation would be:
Code:
@Entity
@NoDuplicarHojaPadronal(groups=JPAGroups.ON_PERSIST)
public class HojaPadronal {


Look also at this thread:
http://forum.hibernate.org/viewtopic.php?t=986527


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 3:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ValidadorNoDuplicarHojaPadronal test based on some data in the database?

This is the typical bad use case for validation unless you use a Serializable transaction isolation :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 2:38 pm 
Beginner
Beginner

Joined: Fri Jan 14, 2005 7:47 am
Posts: 37
Location: Spain
emmanuel wrote:
ValidadorNoDuplicarHojaPadronal test based on some data in the database?

Of course.
Do you mean that JSR-303 will not allow to read database from the constraint logic?

emmanuel wrote:
This is the typical bad use case for validation unless you use a Serializable transaction isolation :)

"bad use case": Let me to decide if it's bad or good.
There are nothing perfect. All options, even the better ones, have its inconvenients.
I think that to forbid access to database from a validator is a great mistake.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 4:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It is not forbidden to use a database in a constraint validator implementation, people are free to shoot themselves in the foot.
But I would be reinsured if you needed the group feature on a non flawed use case :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 6:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Nevermind, there is a use case here. http://forum.hibernate.org/viewtopic.php?t=986527

_________________
Emmanuel


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