Announcement Announcement Module
Collapse
No announcement yet.
Updating domain object via DAO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.

    Example
    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, 04: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:
    Code:
    		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, 06:48 AM. Reason: added comment about my refresh function

    Comment


    • #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.

      Comment


      • #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.

        http://forum.springframework.org/showthread.php?t=12878

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

        Comment


        • #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.

          http://www.onjava.com/lpt/a/6312

          Comment

          Working...
          X