• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Coupling business object and dao

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Cristian Vrabie
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hey cool! They got a blimp! But I have a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic