Hi,
I'd like to ask a JEE design question: Would you define a data-access (DAO) layer ?
For example, say I have a session bean "BankBean", which works on Account Entities.
In most tutorials, I see session beans directly accessing Entity API :
// Session bean directly accessing Entity API:
public class BankBean {
public void someMethod(){
Query query=em.createQuery("select a from Account a where a.ownerName= :n").setParameter("n", ownerName);
List<Account> accounts=query.resultList();
....
}
}
I'm considering an alternative, where Entity API will be encapsulated in a DataAccess layer. I was hoping this would make my Session bean more readable (especially if it's large and complex), and also hide sql implementation decisions (such as query optimization, native SQL, etc).
Something like:
// Data Accesss helper (session beans will use this Dao, instead of directly accessing Entity API):
public class AccountDao {
public List<Account> findAccountsByOwnerName(String ownerName, EntityManager em){
Query query=em.createQuery("select a from Account a where a.ownerName= :n").setParameter("n", ownerName);
return query.getResultList();
}
}
Does this make sense ?
Would this be a common practice for most JEE applications, or is it a root taken only be design freaks... ?
Thanks a lot :)