-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: merge() successful in cache but not written to DB?
PostPosted: Fri Mar 02, 2007 1:28 pm 
Newbie

Joined: Mon Oct 23, 2006 11:03 pm
Posts: 17
I'm new to Hibernate and am obviously missing something basic about
the semantics of merge(). The examples in "Java Persistence with
Hibernate" say that if you have a persistent instance in the
cache and merge a transient instance into it, the updated state will
be written to the database upon commit.

In my case the merge appears to work in the cache. I log the contents
of the merged object returned from merge() and it shows the updates
applied correctly. However, when the commit() runs the log shows
that Hibernate is NOT flushing the updated state to the database, and
checking the database shows that no update was made.

Hibernate version: 3.2.2

Code between sessionFactory.openSession() and session.close():
Code:
            Session session = HibernateUtil.getSessionFactory().openSession();
            log.debug("got session");
           
            tx = HibernateUtil.getUserTransaction();
            log.debug("got transaction");
            tx.begin();

            log.debug("loading team " + t.getId());
            Team x = (Team) session.load(Team.class, t.getId());
            log.debug("Team loaded");
            log.debug(x);
            log.debug("starting merge");
            Team z = (Team) session.merge(t);
            log.debug("merge successful");
            log.debug(z);

            tx.commit();
            log.debug("committed");
            session.close();


Full stack trace of any exception that occurs: N/A

Name and version of the database you are using: Oracle 9

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
Code:
DEBUG [03-02-2007 11:18:19] (DefaultMergeEventListener.java:entityIsDetached:203) - merging detached instance
DEBUG [03-02-2007 11:18:19] (DefaultLoadEventListener.java:proxyOrLoad:171) - loading entity: [com.wholefoods.ittoolkit.ws.admin.Team#1]
DEBUG [03-02-2007 11:18:19] (DefaultLoadEventListener.java:returnNarrowedProxy:214) - entity proxy found in session cache
DEBUG [03-02-2007 11:18:19] (DefaultLoadEventListener.java:doLoad:332) - attempting to resolve: [com.wholefoods.ittoolkit.ws.admin.Team#1]
DEBUG [03-02-2007 11:18:19] (DefaultLoadEventListener.java:doLoad:349) - resolved object in session cache: [com.wholefoods.ittoolkit.ws.admin.Team#1]
DEBUG [03-02-2007 11:18:19] (UpdateTeam.java:update:38) - merge successful
DEBUG [03-02-2007 11:18:19] (UpdateTeam.java:update:39) - Team ID=1 NPS Systems test@test.org 1087
    User 01 uid=tuser01 email=tuser01@wholefoods.com role=3
    User 03 uid=tuser03 email=tuser03@wholefoods.com role=3
    User 05 uid=tuser05 email=tuser05@wholefoods.com role=3
    User 02 uid=tuser02 email=tuser02@wholefoods.com role=4
    Team Leader 01 uid=tldr01 email=tldr01@wholefoods.com role=2
    User 04 uid=tuser04 email=tuser04@wholefoods.com role=4
    Project  1, 1
    Project  1, 2
    Project  1, 3
    Project  1, 4
    Test Added Project

DEBUG [03-02-2007 11:18:19] (CacheSynchronization.java:beforeCompletion:40) - transaction before completion callback
DEBUG [03-02-2007 11:18:19] (JDBCContext.java:beforeTransactionCompletion:201) - before transaction completion
DEBUG [03-02-2007 11:18:19] (SessionImpl.java:beforeTransactionCompletion:393) - before transaction completion
DEBUG [03-02-2007 11:18:19] (CacheSynchronization.java:afterCompletion:82) - transaction after completion callback, status: 3
DEBUG [03-02-2007 11:18:19] (JDBCContext.java:afterTransactionCompletion:215) - after transaction completion
DEBUG [03-02-2007 11:18:19] (SessionImpl.java:afterTransactionCompletion:422) - after transaction completion
DEBUG [03-02-2007 11:18:19] (UpdateTeam.java:update:42) - committed
DEBUG [03-02-2007 11:18:19] (SessionImpl.java:close:273) - closing session
DEBUG [03-02-2007 11:18:19] (ConnectionManager.java:cleanup:373) - connection already null in cleanup : no action


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 02, 2007 1:50 pm 
Newbie

Joined: Mon Oct 23, 2006 11:03 pm
Posts: 17
Closer reading reveals that flush() occurs only if one is using Hibernate's
builtin transaction management. I was using JTA directly.

I will switch to Hibernate's transaction mechanism.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.