Results 1 to 7 of 7

Thread: Domain objects with no dependencys on DAO's

  1. #1
    Join Date
    Apr 2005
    Posts
    18

    Default Domain objects with no dependencys on DAO's

    Hi,

    I have a partitioning question that I'd some feedback on.

    Our app uses Spring, Struts and Hibernate, and I'd like to keep our domain model (the Hibernate POJO's) from having any dependencies on our DAO's (that wrap Hibernate). However, consider a domain object that has the business rule that a certain property must be unique. How can this be implemented so that the domain object enforces this business rule, but without having to directly call a DAO in the domain object to enforce it?


    many thanks,

    drc

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Can this logic just be applied in the services layer?

    I assume this will be enforced by the DB, so you can have a services method to check the name is available, and also logic to handle data integrity violations.

  3. #3
    Join Date
    Apr 2005
    Posts
    18

    Default

    katentim ,

    yeah it could be, but I see this as something that ideally belongs in the domain object - which then requires a reference to a DAO to do this, which I dont like.

    The other issue is that we are using the same 'Services' object for all CRUD type operations from the UI - which means that I can not check for uniqueness in the services layer.


    thanks.

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    The other issue is that we are using the same 'Services' object for all CRUD type operations from the UI - which means that I can not check for uniqueness in the services layer.
    I don't think I follow. Why can't the services layer check for uniqueness? Is this a caching issue?

  5. #5
    Join Date
    Apr 2005
    Posts
    18

    Default

    Firstly a definition, our struts actions call into our 'Services' tier. This services tier is generic so it accepts a Collection of domain objects and simply persists them to the db - regardless of what type they are. Each domain object has a method where we put validations, so this method is called prior to persisting it to the db. Given that this Services object is generic, it cant do domain-specific type validations.

    The reason why we have such a generic services object is because we have many simple CRUD-type html screens.

    I hope this helps.

  6. #6
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Given that this Services object is generic, it cant do domain-specific type validations
    You could possibly use AOP to apply advice on add methods in the service layer for certain domain object types.

  7. #7
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Why can't your validator simply ask the DAO to check the uniqueness?

    Sure there is still a window of opportunity to get inconsistent results, but it is a very *very* small one and the DB will throw an exception so it is safe.....

    Is it unique within a parent? If so, then why not implement hashCode and equals and just check adding it to the parent's set of children?

Similar Threads

  1. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  2. Replies: 12
    Last Post: Jun 21st, 2005, 01:28 PM
  3. Binding to business domain objects
    By klr8 in forum Architecture
    Replies: 2
    Last Post: Mar 15th, 2005, 01:21 AM
  4. Replies: 0
    Last Post: Jan 6th, 2005, 08:19 AM
  5. Should Business Objects have References to DAOs?
    By sethladd in forum Architecture
    Replies: 9
    Last Post: Aug 25th, 2004, 01:18 PM

Posting Permissions

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