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