Search code examples
javajakarta-eedesign-patternsfacade

findByUsername or find method of Facade absract class


I'm trying to make a Login app with JSF, and I found in forums that a lot of people use LoginByUsername(or findByUsername or whatever they call it ,anyway a method that does find the username and returns the user and uses SQL) and they put it in the facade(session bean for entity class) ! But the facade itself gives us something called find(Object id) ,and the id is username . so what's better : using find or making its own method(that uses SQL)? and why?

thanks in advance for your help


Solution

  • If the username is used as id in your app, then it's no need to write a new method LoginByUsername/findByUsername, since you have already have the method find(Object id), which can achieve the function findByUsername will do.

    But, since it's a Login App, i think it's better to provide a method called findByUserAndPassword, and if no result is returned, tell the user that user or password is wrong, which it's commonly used in many website.