ypap77 wrote:
I m new to all this so i have the following question.
Let’s say i have a domain model with POJOS and DAO objects for each of this pojos that do all the data access work using hibernate.
I want to ask if it would be bad practice to use a DAO object inside the getter of a collection preperty of the domain model class in order to populate this collection if its empty.
I understant that it is best for performance to initialize all the data is needed with hql (using eager fetching strategies for the collections we need) but maybe thats not possible every time or its not practical
No, no, absolutely no.
Do not mix layers. In a simple architecture with database+servlet container, your POJO's are your business objects: they contain the data model.
DAO,s, on the contrary, are the "mechanical" way to access data.
You should write your BO, application logic and DAO's in a way that, for example, if you'll decide to abandon Hibernate in the future, all you have to do is rewrite DAO's; not BO and application logic code (services/managers/process oriented b.o., call these with the name you prefer).
I suspect that you don't know "Open Session in View pattern": take a look at this.
Delta