Juan has made a good suggestion. You can use the conversational state of
stateful session bean to hold the data without committing it, which gives you a
chance to validate it before its applied to the entity bean.. This should only
be done, however, if the stateful session bean models a process -- it should
not wrapper the entity bean only to provide validation.  That would be too much
indirection to make it worthwhile.

You can also do combinatorial validation (validation of attributes in
combination) using bulk accessors.  If a particular set of attributes need to
be compared in order to be validated they can be submitted together using a
bulk data object.  This avoids the problem associated with modifying one
attribute at a time only to discover that the combination doesn't work.

Its also possible to put the combinatorial validation logic in the bulk data
object itself, so that the data can be validated on the client before it sent
to the server.  In this case the validation logic should be fairly simple,
because, ideally, you want to keep more complex business logic in the bean.

--
Richard Monson-Haefel
Author of Enterprise JavaBeans, 2nd Edition
Published by O'Reilly & Associates
http://www.EjbNow.com


Juan Pablo Lorandi wrote:

> Facade your Entity Beans with a Session Bean and perform form-level
> Validation (and other Biz Logic) in it.
>
> Just a thought,
>
> JP
>
> -----Original Message-----
> From: Andr�s Aguiar [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, September 07, 2000 12:54 PM
> To: [EMAIL PROTECTED]
> Subject: Validation
>
> I'm a newbie in Entity Beans, and I can't find the proper place to validate
> the  bean's attributes.
>
> The simple way is to throw an application exception when some business rule
> is broken when you set an attribute. For example
>
> public void setQuantity(int value)
> {
>         if (value < 0)
>                 throw new InvalidQuantityException();
>
>         ...
> }
>
> but what if the business rule needs the value of 2 or more attributes? I
> don't want to throw the exception in each 'set' method because I want the
> bean user to be able to set the attributes in any order.
>
> I need some 'validate' method that must be called when the bean is
> 'complete'..
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to