Announcement Announcement Module
No announcement yet.
Updating domain object via DAO Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Updating domain object via DAO

    Hello forum users,

    I am searching for a solution that the same domain objects (equals id) which were loaded twice or several times by the DAO will be get persistent after DAO update.

    Domain object A will loaded by a DAO method maby "DomainObject getByAttribute(..)".
    The same domain object B (with same id) will load by a DAO method like "List<DomainObject> getAll()".
    After editing A and updating it via DAO update, B should be reloaded.

    I thought for this task mabye a DomainObjectManager or something like this would be practicable which will be the source for the business logic and talk to the DAOs.
    The background is two use this behaviour for binding the domain objects to gui components. Naturally the domain objects will be observable in any form.

    I would not surprised if there is another more usefull solution.

    Thank you for any kinds of suggestions.

    regards qpid
    Last edited by qpid; Feb 23rd, 2007, 03:25 AM.

  • #2
    As long as the domain object loaded in your first get, is not disconnected from the hibernate session, you'll get the exact same object in the collection loaded in your second get.

    Meaning you don't need a refresh at all, there is only 1 object.

    Simple junit test that illustrates this:
    		Payment payment = getPaymentPersistent();
    		//run on empty database, so the only persistent object is the one from the last line
    		Payment payment2 = paymentDao.getAll().get( 0 );
    		String name = payment.getName();
    		payment.setName( name + "notsame" );
    		paymentDao.update( payment );
    		paymentDao.refresh( payment ); //flush + refresh
    		assertNotSame( name, payment.getName() );
    		assertSame( payment.getName(), payment2.getName() );
    Maybe this helps you...
    Last edited by Daniel Rijkhof; Feb 23rd, 2007, 05:48 AM. Reason: added comment about my refresh function


    • #3
      Yeah you are right, if i use hibernate there is no problem, but if i don't use hibernate or some other full or-mapper but Spring JdbcTemplate.

      But maby this is a feature which comes only with a complex technologie like hibernate. So there is no simple way to realize this.

      So there is still a diffrent behaviour, although it programmed against interfaces.


      • #4
        I searched i little bit more and found a thread with nearly the same problem. The keyword is caching the domain objects in the dao's. So the behaviour outwards will be the same like hibernate with sessions.

        So my question is than if anyone knows a well implementation of such a domain object cache?


        • #5
          Have you used PojoCache? Maybe it can do exactly what you want with a bit of configuration.

          PojoCache performs fine-grained field level (using AOP) replication object mapping and relationship management for a user behind the scenes. It can be used in local or replicated mode.