aspose file tools
The moose likes Object Relational Mapping and the fly likes Coupling business object and dao Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "Coupling business object and dao" Watch "Coupling business object and dao" New topic
Author

Coupling business object and dao

Cristian Vrabie
Ranch Hand

Joined: Jul 09, 2008
Posts: 71
Hi guys!
I'm new to Java and I'm now studying Spring + Hibernate. In the samples I found on the web there were business objects with methods like:



The UserDao class is a bean injected from Spring and would make the call to hiberate and stuff.

But that's not rights is it? I mean, this is coupling the data access layer with your business model. From what I can remember the business model should not know about about dao's. Or is it? It's true I can think of some situations where injecting the dao in the business class would come in handy but that's just because i don't know more about hibernate.

Thanks in advance and sorry if my question is silly
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17243
    
    1

Isn't this a case where the dao knows the domain object, but the domain objects still don't know about the daos. Couldn't you also have Spring inject the domain objects into the daos?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Cristian Vrabie
Ranch Hand

Joined: Jul 09, 2008
Posts: 71
well the point was that you usually have one dao and many domain object. you can't inject them all in the dao. you don't even know when they'll get instantiated
Cristian Vrabie
Ranch Hand

Joined: Jul 09, 2008
Posts: 71
actually i might be mistaken. one layer should be allowed to know only about the layer directly below and dao is directly under domain layer. so it actually could be correct. i just got confused because i saw different implementations of the same sample problem in many different ways.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Coupling business object and dao
 
Similar Threads
Calling DAO from session scoped bean
Looking for advice on configuring a new project using Spring and Hibernate.
Mapping interfaces in Hibernate
S2: Action/DAO mess...
Data Access Objects: static methods