Page 11 of 11 FirstFirst ... 91011
Results 101 to 102 of 102

Thread: DAO Reference Inside an Entity Domain Object?

  1. #101

    Default

    So, do you even model the relationship in the parent class in that case, i.e. with a private data member of type List<Car>, for example? Would your CarCompany look like:

    Code:
    public class CarCompany
    {
        private List<Car> cars;
        private CarLocator carLocator;
    
        public List<Car> getCars() 
        {
            if (cars == null)
                cars = carLocator.getCars();
    
            return this.cars; 
        }
    }
    or would it look like this:

    Code:
    public class CarCompany
    {
        private CarLocator carLocator;
    
        public List<Car> getCars() 
        {
            return carLocator.getCars(); 
        }
    }
    The problem with the first option is that it seems redundant - should you handle relationship caching in your domain model? The second option, though, looks like an anemic model from the inside. From the outside, you still see the same behavior, namely CarCompany.getCars(), for example, but the inside is barren.

    If you went to an ORM solution like Hibernate, I would think that you'd want the first option, so that Hibernate could manage that parent-child relationship. You would also have the option of dumping the CarLocator entirely and have Hibernate lazy-load the cars child relationship.

    Where do you draw the line with Hibernate regarding injecting locators and letting Hibernate manage the parent-child relationships? Would you maybe have a CarCompany that looks like this:

    Code:
    public class CarCompany
    {
        private List<Car> cars;
        private List<Factory> factories;
        private CarLocator carLocator;
    
        public List<Car> getCars() 
        {
            if (cars == null)
                cars = carLocator.getCars();
    
            return this.cars; 
        }
    
        public List<Factory> getFactories() { return this.factories; }
    }
    In this case, you'd have Hibernate manage the factories relationship and then use the DAO for the cars one.

    The problem is that I've got a richly-connected domain, and I'm trying to decide where you draw the line between populating the parent-child relationships at object instantiation, whether in the data access object or in the ORM persistence layer, or using locator or DAO services to load those relationships on-demand.

    Thoughts? Anyone else encounter this kind of situation?

  2. #102
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello DFielder

    thanks for the reply, i follow the fairly and nice logic of the book Pro Spring, about transactions

    if i am wrong, please teach me, share information is a good practice

    Manager/Model layer (BO and ADO objects)
    1:
    for the ADO objects i work using Hibernate, so this consist in one interface myinterfaceADO and its myclassADO (that implements the interface ADO)
    here happens the CRUD logic for an entity (Worker,Customer,Payment etc etc)

    2:
    but for the BO objetcs
    same case an interface BO(same methods that the ADO objects for example insertCustomerBO ),
    an abstract class (father) that implemts the interface BO (but really the implementation not happens here) that work with the ADO services "interfaces" and lastly a Default class (concrete) that extends from the abstract class and this concrete class really implements the BO interface

    so in the abstract BO have the ADO interfaces references and call the ADO methods how insertCustomerADO( ... ) in the concrete class (son of the abstract) maybe could has other methods independently of the father and other concrete class that extends from the same father too, the father should has of course the common methods for all the children, validation and call the ADO methods and other methods necessary for the business

    i work with Struts/Hibernate/Spring

    i hope that i was failry with this explain, my english is not perfect

    regards
    Last edited by dr_pompeii; Nov 24th, 2006 at 01:42 PM.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Similar Threads

  1. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. Other Hibernate DAO LazyInitializationExceptions
    By bernardsirius in forum Data
    Replies: 5
    Last Post: Feb 18th, 2005, 04:09 PM
  4. Replies: 9
    Last Post: Feb 8th, 2005, 09:25 PM
  5. Replies: 0
    Last Post: Jan 6th, 2005, 08:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •