[Hibernate] Connection Handling in Isolater
Hi all, I think org.hibernate.engine.transaction.Isolater is not handling connections properly: The method JdbcDelegate is currently implemented as follows: public static class JdbcDelegate implements Delegate { ... public void delegateWork(IsolatedWork work) throws HibernateException { Connection connection = null; try { connection = session.getBatcher().openConnection(); ... } ... } finally { if ( wasAutoCommit ) { try { connection.setAutoCommit( true ); } catch( Throwable ignore ) { log.trace( "was unable to reset connection back to auto-commit" ); } session.getBatcher().closeConnection( connection ); } } } } This means that the connection will only be closed if wasAutoCommit==true but I think it should be closed in any circumstance: public static class JdbcDelegate implements Delegate { ... public void delegateWork(IsolatedWork work) throws HibernateException { Connection connection = null; try { connection = session.getBatcher().openConnection(); ... } ... } finally { if ( wasAutoCommit ) { try { connection.setAutoCommit( true ); } catch( Throwable ignore ) { log.trace( "was unable to reset connection back to auto-commit" ); } } session.getBatcher().closeConnection( connection ); } } } What do you think ? -- "Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] Connection Handling in Isolater
Hello Steve, thanks for the quick reply. Since I didn't notice you've moved to SVN I've checked the "latest" version from CVS (via the web CVS View) ;-) Rgds Holger Steve Ebersole wrote: >Yep. This has already been fixed for almost two months now in SVN ;) > >-Original Message- >From: [EMAIL PROTECTED] >[mailto:[EMAIL PROTECTED] On Behalf Of >[EMAIL PROTECTED] >Sent: Thursday, July 20, 2006 8:35 AM >To: hibernate-devel@lists.sourceforge.net >Cc: [EMAIL PROTECTED] >Subject: [Hibernate] Connection Handling in Isolater > >Hi all, > >I think org.hibernate.engine.transaction.Isolater is not handling >connections properly: > >The method JdbcDelegate is currently implemented as follows: > > public static class JdbcDelegate implements Delegate { > ... > public void delegateWork(IsolatedWork work) throws >HibernateException { > Connection connection = null; > try { > connection = >session.getBatcher().openConnection(); > ... > } > ... > } > finally { > if ( wasAutoCommit ) { > try { > >connection.setAutoCommit( true ); > } > catch( Throwable ignore ) { > log.trace( "was unable >to reset connection back to auto-commit" ); > } > >session.getBatcher().closeConnection( connection ); > } > } > } > } > > >This means that the connection will only be closed if >wasAutoCommit==true but I think it should be closed in any circumstance: > > > public static class JdbcDelegate implements Delegate { > ... > public void delegateWork(IsolatedWork work) throws >HibernateException { > Connection connection = null; > try { > connection = >session.getBatcher().openConnection(); > ... > } > ... > } > finally { > if ( wasAutoCommit ) { > try { > >connection.setAutoCommit( true ); > } > catch( Throwable ignore ) { > log.trace( "was unable >to reset connection back to auto-commit" ); > } > } > session.getBatcher().closeConnection( >connection ); > } > } > } > >What do you think ? > -- "Feel free" – 10 GB Mailbox, 100 FreeSMS/Monat ... Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
[Hibernate] logging AbstractSaveEventListener#performSave
Hi, I'm trying to debug/fix Hibernate messages like "org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: "... and I find the default exception logging in AbstractSaveEventListener#performSave not sufficient. I've added some System.err.printlns() with the information I typically need. It would be great if this debug info would make it somehow into the latest SVN. Rgds Holger /** * Ppepares the save call by checking the session caches for a pre-existing * entity and performing any lifecycle callbacks. * @param entity The entity to be saved. * @param id The id by which to save the entity. * @param persister The entity's persister instance. * @param useIdentityColumn Is an identity column in use? * @param source The session from which the event originated. * @param requiresImmediateIdAccess does the event context require * access to the identifier immediately after execution of this method (if * not, post-insert style id generators may be postponed if we are outside * a transaction). * @return The id used to save the entity; may be null depending on the * type of id generator used and the requiresImmediateIdAccess value * @throws HibernateException */ protected Serializable performSave( Object entity, Serializable id, EntityPersister persister, boolean useIdentityColumn, Object anything, EventSource source, boolean requiresImmediateIdAccess) throws HibernateException { if ( log.isTraceEnabled() ) { log.trace( "saving " + MessageHelper.infoString( persister, id, source.getFactory() ) ); } EntityKey key; if ( !useIdentityColumn ) { key = new EntityKey( id, persister, source.getEntityMode() ); Object old = source.getPersistenceContext().getEntity(key); if (old != null) { if ( source.getPersistenceContext().getEntry(old).getStatus() == Status.DELETED ) { source.forceFlush( source.getPersistenceContext().getEntry(old) ); } else { System.err.println("old: " + old); System.err.println("old.class: " + old.getClass()); System.err.println("entity: " + entity); System.err.println("entity.class: " + entity.getClass()); System.err.println("id: " + id); throw new NonUniqueObjectException( id, persister.getEntityName() ); } } persister.setIdentifier(entity, id, source.getEntityMode()); } else { key = null; } if ( invokeSaveLifecycle(entity, persister, source) ) { return id; //EARLY EXIT } return performSaveOrReplicate( entity, key, persister, useIdentityColumn, anything, source, requiresImmediateIdAccess ); } -- Echte DSL-Flatrate dauerhaft für 0,- Euro*! "Feel free" mit GMX DSL! http://www.gmx.net/de/go/dsl - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel
Re: [Hibernate] logging AbstractSaveEventListener#performSave
Here you go: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1934 it's only three lines, but enhances two logging entries, so will I have three lines free on the next issue ;-) ?? anyway, I'd really like to see the logging on those issues improved, since I've spent quite some time to hunt them down (I suppose other people will have the same problems). thanks for the good work :-) Max Rydahl Andersen wrote: > > submit a patch in jira that sends it to log.trace (in less than 4 individual > lines ;) and we will consider it. > > /max > >> Hi, >> >> I'm trying to debug/fix Hibernate messages like >> "org.hibernate.NonUniqueObjectException: a different object with the same >> identifier value was already associated with the session: "... and I find >> the default exception logging in AbstractSaveEventListener#performSave not >> sufficient. I've added some System.err.printlns() with the information I >> typically need. It would be great if this debug info would make it somehow >> into the latest SVN. >> >> Rgds >> Holger >> >> /** >> * Ppepares the save call by checking the session caches for a >> pre-existing >> * entity and performing any lifecycle callbacks. >> * @param entity The entity to be saved. >> * @param id The id by which to save the entity. >> * @param persister The entity's persister instance. >> * @param useIdentityColumn Is an identity column in use? >> * @param source The session from which the event originated. >> * @param requiresImmediateIdAccess does the event context require >> * access to the identifier immediately after execution of this method >> (if >> * not, post-insert style id generators may be postponed if we are >> outside >> * a transaction). >> * @return The id used to save the entity; may be null depending on the >> * type of id generator used and the requiresImmediateIdAccess value >> * @throws HibernateException >> */ >> protected Serializable performSave( >> Object entity, >> Serializable id, >> EntityPersister persister, >> boolean useIdentityColumn, >> Object anything, >> EventSource source, >> boolean requiresImmediateIdAccess) >> throws HibernateException { >> >> if ( log.isTraceEnabled() ) { >> log.trace( >> "saving " + >> MessageHelper.infoString( persister, id, >> source.getFactory() ) >> ); >> } >> >> EntityKey key; >> if ( !useIdentityColumn ) { >> key = new EntityKey( id, persister, source.getEntityMode() ); >> Object old = source.getPersistenceContext().getEntity(key); >> if (old != null) { >> if ( >> source.getPersistenceContext().getEntry(old).getStatus() == Status.DELETED >> ) { >> source.forceFlush( >> source.getPersistenceContext().getEntry(old) ); >> } >> else { >> System.err.println("old: " + old); >> System.err.println("old.class: " + old.getClass()); >> System.err.println("entity: " + entity); >> System.err.println("entity.class: " + entity.getClass()); >> System.err.println("id: " + id); >> throw new NonUniqueObjectException( id, >> persister.getEntityName() ); >> } >> } >> persister.setIdentifier(entity, id, source.getEntityMode()); >> } >> else { >> key = null; >> } >> >> if ( invokeSaveLifecycle(entity, persister, source) ) { >> return id; //EARLY EXIT >> } >> >> return performSaveOrReplicate( >> entity, >> key, >> persister, >> useIdentityColumn, >> anything, >> source, >> requiresImmediateIdAccess >> ); >> } >> > > > -- Holger Haag Geschäftsführer SoftConEx GmbH Zossener Straße 55 D-10961 Berlin Telefon: ++49 (0) 30 63901692 Fax: ++49 (0) 30 63901669 Mobil: ++49 (0) 1511 7810317 -- Echte DSL-Flatrate dauerhaft für 0,- Euro*. Nur noch kurze Zeit! "Feel free" mit GMX DSL: http://www.gmx.net/de/go/dsl - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV ___ hibernate-devel mailing list hibernate-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/hibernate-devel