aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes EJB Exception design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB Exception design" Watch "EJB Exception design" New topic
Author

EJB Exception design

Raj Bhandari
Ranch Hand

Joined: Oct 19, 2005
Posts: 97
Hi everyone,
Perhaps a simple question.
Say for Example I have a createStudent method as follows in my bean:



Now when I call this method in my action(struts) everything works fine but what is bothering me is that I don't want the error from the EJB layer to come up one by one.
So, on the UI when I forget entering both name and age.
I get error saying "name is required" and when I fill that, I get "age is required". Is there a good way I can add up the messages and send it back to the client/action calling it. Should I be throwing Exception or something else? Is there a way to include lists in exceptions?

Note- I understand I can do validation on client side also for required fields. But this is a simple example; there could be business logic validations on EJB and I want to add them up and send all at once.

Tks!
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Raj,

There is no easy way other than hand-coding validation error roll-up. However, you might want to check out Hibernate validator: http://www.hibernate.org/412.html - it is being standardized in Java EE 6 as JSR 303: http://jcp.org/en/jsr/detail?id=303.

Regards,
Reza
[ November 21, 2008: Message edited by: Reza Rahman ]

Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Raj Bhandari
Ranch Hand

Joined: Oct 19, 2005
Posts: 97
Raza, tks for the reply.
Any other suggestions by anyone are welcome :-)
Tks
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9351
    
    2

Originally posted by Reza Rahman:
Raj,

There is no easy way other than hand-coding validation error roll-up. However, you might want to check out Hibernate validator: http://www.hibernate.org/412.html - it is being standardized in Java EE 6 as JSR 303: http://jcp.org/en/jsr/detail?id=303.

Regards,
Reza

[ November 21, 2008: Message edited by: Reza Rahman ]


I've worked with Hibernate before but never used Hibernate Validators. But offlate I'm working on EJB 3 and very soon I will be implementing JPA for my current project. I would like to know if I can use these Validators for my JPA? All I would have to do it to include the validator.jar file in my classpath? Am I right?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
 
jQuery in Action, 2nd edition
 
subject: EJB Exception design