There is no such "best practice" specific to EJB (especially as of EJB 3), other than the basic practices of writing good Java code. In case of what you are describing, returning boolean seems incorrect. you should probably return a higher level "result" object that returns both the boolean and the message.
Java Exceptions carry a message payload as part of the base Exception class definition. Plus, if you need additional context, you can also add that to your exception.
Originally posted by Abhijit Das:
But Exception is a heavy object. While login failure is so common and frequently occurs (due to wrong username / password). It is probably not a good solution to throw user defined exception object. performance gets affected..
please correct me if I am wrong!!!
They are something related to a business, I mean the LoginFailException. What else could you do when your Business rule fails to validate?? You could throw a Business Exception with a message of why it failed. So I'd say, it is ideal to throw a user defined exception like the LoginFailException to the client which should contain everything of why it occurred.