I'm attempting to use Hibernate within a non-J2EE free standing app to simplify how we persist Java objects into a DB. My "pattern" initially appears extremely simple, but the 2nd and subsequent transactions don't appear to trigger SQL BEGIN/COMMIT/ROLLBACK within the Postgres back-end. Here's a test code fragment:
Code:
// Create some test objects
YAWLServiceReference obj1 = new YAWLServiceReference("TEST1", null);
YAWLServiceReference obj2 = new YAWLServiceReference("TEST2", null);
YAWLServiceReference obj3 = new YAWLServiceReference("TEST3", null);
YAWLServiceReference obj4 = new YAWLServiceReference("TEST4", null);
YAWLServiceReference obj5 = new YAWLServiceReference("TEST5", null);
YAWLServiceReference obj6 = new YAWLServiceReference("TEST6", null);
// Persist
session = factory.openSession();
con = session.connection();
[color=red]tx = session.beginTransaction();[/color]
session.save(obj1);
session.save(obj2);
session.save(obj3);
[color=red]tx.commit();[/color]
[color=red]session.close();[/color]
session = null;
// Persist
session = factory.openSession(con);
[color=red]tx = session .beginTransaction();[/color]
session.save(obj4);
session.save(obj5);
session.save(obj6);
[color=red] tx.commit();[/color]
[color=red] session.close();[/color]
Whilst the Hibernate debug trace shows a transaction being started and commited within both "sessions", the trace within the Postgres back-end does not show a transaction for the second "session". Here's the Postgres trace (using SQL trace option in postgresql.conf):
Code:
LOG: statement: SHOW TRANSACTION ISOLATION LEVEL
LOG: statement: BEGIN
LOG: statement: insert into services (documentation, serviceid) values ($1, $2)
LOG: statement: insert into services (documentation, serviceid) values ($1, $2)
LOG: statement: insert into services (documentation, serviceid) values ($1, $2)
LOG: statement: COMMIT
LOG: statement: insert into services (documentation, serviceid) values ($1, $2)
LOG: statement: insert into services (documentation, serviceid) values ($1, $2)
LOG: statement: insert into services (documentation, serviceid) values ($1, $2)
LOG: could not receive data from client: Connection reset by peer
LOG: unexpected EOF on client connection
Any clues as to why I see this behaviour?. I suppose the "trace" within Postgresql could be at fault here, but I don't believe that to be the case.
Hibernate version: Hibernate 2.1.4
Mapping documents:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="au.edu.qut.yawl.elements.YAWLServiceReference" table="services">
<id name="_yawlServiceID" column="serviceid" type="string" access="field">
<generator class="assigned"/>
</id>
<property name="_documentation" column="documentation" access="field"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():See example code fragment above.Full stack trace of any exception that occurs:Name and version of the database you are using:PostgreSQL 7.4.5
The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code:
INFO - Hibernate 2.1.4
INFO - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.postgresql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.ehcache.hibernate.Provider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.connection.username=yawl, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:postgresql:yawl, hibernate.show_sql=true, hibernate.connection.password=yawl, hibernate.transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, hibernate.connection.pool_size=5}
INFO - using java.io streams to persist binary types
INFO - using CGLIB reflection optimizer
INFO - Mapping resource: au/edu/qut/yawl/elements/YAWLServiceReference.hbm.xml
DEBUG - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under net/sf/hibernate/
DEBUG - found http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath
INFO - Mapping class: au.edu.qut.yawl.elements.YAWLServiceReference -> services
DEBUG - Mapped property: _yawlServiceID -> serviceid, type: string
DEBUG - Mapped property: _documentation -> documentation, type: string
INFO - processing one-to-many association mappings
INFO - processing one-to-one association property references
INFO - processing foreign key constraints
INFO - Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
INFO - Maximim outer join fetch depth: 1
INFO - Use outer join fetching: true
INFO - Using Hibernate built-in connection pool (not for production use!)
INFO - Hibernate connection pool size: 5
INFO - using driver: org.postgresql.Driver at URL: jdbc:postgresql:yawl
INFO - connection properties: {user=yawl, password=yawl}
INFO - [color=red]Transaction strategy: net.sf.hibernate.transaction.JDBCTransactionFactory[/color]
INFO - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
DEBUG - total checked-out connections: 0
DEBUG - opening new JDBC connection
DEBUG - created connection to: jdbc:postgresql:yawl, Isolation Level: 2
DEBUG - returning connection to pool, pool size: 1
INFO - Use scrollable result sets: true
INFO - Use JDBC3 getGeneratedKeys(): false
INFO - Optimize cache for minimal puts: false
INFO - echoing all SQL to stdout
INFO - Query language substitutions: {no='N', yes='Y'}
INFO - cache provider: net.sf.ehcache.hibernate.Provider
INFO - instantiating and configuring caches
INFO - building session factory
DEBUG - instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=yawl, hibernate.cache.provider_class=net.sf.ehcache.hibernate.Provider, sun.boot.library.path=C:\jdk1.4.2\jre\bin, java.vm.version=1.4.2-b28, hibernate.connection.username=yawl, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, hibernate.cache.use_query_cache=true, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, idea.launcher.port=7551, user.country=GB, sun.os.patch.level=Service Pack 4, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\StarTeam\YawlRuntimeM2\ide, java.runtime.version=1.4.2-b28, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\jdk1.4.2\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows 2000, sun.java2d.fontpath=, hibernate.cache.region_prefix=hibernate.test, java.library.path=C:\jdk1.4.2\bin;.;E:\WINNT\system32;E:\WINNT;C:\PROGRAM FILES\THINKPAD\UTILITIES;E:\WINNT\system32;E:\WINNT;E:\WINNT\System32\Wbem;E:\Program Files\Microsoft SQL Server\80\Tools\BINN;E:\Program Files\Symantec\pcAnywhere\;E:\Program Files\Borland\StarTeam SDK 6.0\Lib;E:\PROGRA~1\CA\SHARED~1\SCANEN~1;E:\PROGRA~1\CA\ETRUST~1;E:\Program Files\Common Files\Ulead Systems\MPEG;E:\Program Files\Common Files\Ulead Systems\DVD;C:\graphviz\Graphviz\bin;C:\graphviz\Graphviz\bin\tools;E:\Program Files\Common Files\GTK\2.0\bin;E:\Program Files\Borland\StarTeam SDK 2005\Lib;E:\Program Files\Borland\StarTeam SDK 2005\Bin;C:\apache-ant-1.6.1\bin;c:\cygwin\bin;e:\progra~1\putty, java.specification.name=Java Platform API Specification, java.class.version=48.0, hibernate.connection.pool_size=5, hibernate.transaction.factory_class=net.sf.hibernate.transaction.JDBCTransactionFactory, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.0, user.home=E:\Documents and Settings\ahastie, user.timezone=Europe/London, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=windows-1252, java.specification.version=1.4, hibernate.connection.driver_class=org.postgresql.Driver, java.class.path=C:\jdk1.4.2\jre\lib\charsets.jar;C:\jdk1.4.2\jre\lib\jce.jar;C:\jdk1.4.2\jre\lib\jsse.jar;C:\jdk1.4.2\jre\lib\plugin.jar;C:\jdk1.4.2\jre\lib\rt.jar;C:\jdk1.4.2\jre\lib\sunrsasign.jar;C:\jdk1.4.2\jre\lib\ext\dnsns.jar;C:\jdk1.4.2\jre\lib\ext\ldapsec.jar;C:\jdk1.4.2\jre\lib\ext\localedata.jar;C:\jdk1.4.2\jre\lib\ext\sunjce_provider.jar;C:\StarTeam\YawlRuntimeM2\classes;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\lib\jaxen-core.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\lib\jaxen-jdom.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\lib\jdom.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\lib\junit.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\lib\postgresql-8.0-311.jdbc3.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\lib\saxon7.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\lib\saxpath.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\lib\servlet-api.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\lib\xercesImpl.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\apache_soap-2_3_1.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\axis-1.1RC2.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\axis-1_1RC2-ant.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\commons-discovery.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\commons-logging.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\j2ee.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\jaxrpc.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\jdom.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\log4j-1_2_4.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\optional-1_5_1.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\qname-from-wsdl4j-20030807.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\saaj.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\soaprmi-1_1.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\wsdl4j-20030807.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\wsif-j2c.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\wsif.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\xercesImpl-2_2_1.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\wsif-lib\xmlParserAPIs-2_2_1.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\xsdlib\common.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\xsdlib\ecore.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\xsdlib\xsd.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\xsdlib\xsd.resources.jar;C:\StarTeam\Java\JavaCommons\log4j-1.2.8.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\persistenceLibs\cglib-full-2.0.1.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\persistenceLibs\commons-collections-2.1.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\persistenceLibs\commons-logging-1.0.3.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\persistenceLibs\dom4j-1.4.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\persistenceLibs\ehcache-0.7.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\persistenceLibs\hibernate2.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\persistenceLibs\hsqldb.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\persistenceLibs\jta.jar;C:\StarTeam\YAWL_QUT\runtime\build\3rdParty\persistenceLibs\odmg-3.0.jar;C:\IDEA_4_5_4\lib\idea_rt.jar, user.name=ahastie, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.show_sql=true, java.vm.specification.version=1.0, java.home=C:\jdk1.4.2\jre, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, hibernate.connection.url=jdbc:postgresql:yawl, user.language=en, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, hibernate.jdbc.use_streams_for_binary=true, java.version=1.4.2, java.ext.dirs=C:\jdk1.4.2\jre\lib\ext, sun.boot.class.path=C:\jdk1.4.2\jre\lib\rt.jar;C:\jdk1.4.2\jre\lib\i18n.jar;C:\jdk1.4.2\jre\lib\sunrsasign.jar;C:\jdk1.4.2\jre\lib\jsse.jar;C:\jdk1.4.2\jre\lib\jce.jar;C:\jdk1.4.2\jre\lib\charsets.jar;C:\jdk1.4.2\jre\classes, java.vendor=Sun Microsystems Inc., hibernate.jdbc.batch_size=0, file.separator=\, idea.launcher.library=C:\IDEA_4_5_4\bin\breakgen.dll, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, hibernate.max_fetch_depth=1, sun.cpu.isalist=pentium i486 i386}
DEBUG - initializing class SessionFactoryObjectFactory
DEBUG - registered: 8a1694c404e2d0e30104e2d0e75f0000 (unnamed)
INFO - no JNDI name configured
DEBUG - instantiated session factory
INFO - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
DEBUG - Creating new CacheManager with default config
DEBUG - Configuring ehcache from classpath.
WARN - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/StarTeam/YAWL_QUT/runtime/build/3rdParty/persistenceLibs/ehcache-0.7.jar!/ehcache-failsafe.xml
DEBUG - Disk Store Path: C:\Temp\
WARN - Could not find configuration for net.sf.hibernate.cache.UpdateTimestampsCache. Configuring using the defaultCache settings.
DEBUG - net.sf.hibernate.cache.UpdateTimestampsCache Cache: Using SpoolingLinkedHashMap implementation
DEBUG - initialized MemoryStore for net.sf.hibernate.cache.UpdateTimestampsCache
INFO - starting query cache at region: net.sf.hibernate.cache.QueryCache
DEBUG - Attempting to create an existing instance. Existing instance returned.
WARN - Could not find configuration for net.sf.hibernate.cache.QueryCache. Configuring using the defaultCache settings.
DEBUG - net.sf.hibernate.cache.QueryCache Cache: Using SpoolingLinkedHashMap implementation
DEBUG - initialized MemoryStore for net.sf.hibernate.cache.QueryCache
DEBUG - opened session
DEBUG - total checked-out connections: 0
DEBUG - using pooled JDBC connection, pool size: 0
DEBUG - [color=red]begin[/color]
DEBUG - current autocommit status:false
DEBUG - generated identifier: TEST1
DEBUG - saving [au.edu.qut.yawl.elements.YAWLServiceReference#TEST1]
DEBUG - generated identifier: TEST2
DEBUG - saving [au.edu.qut.yawl.elements.YAWLServiceReference#TEST2]
DEBUG - generated identifier: TEST3
DEBUG - saving [au.edu.qut.yawl.elements.YAWLServiceReference#TEST3]
[color=red]DEBUG - commit
DEBUG - flushing session[/color]
DEBUG - Flushing entities and processing referenced collections
DEBUG - Processing unreferenced collections
DEBUG - Scheduling collection removes/(re)creates/updates
DEBUG - Flushed: 3 insertions, 0 updates, 0 deletions to 3 objects
DEBUG - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG - listing entities:
DEBUG - au.edu.qut.yawl.elements.YAWLServiceReference{_documentation=null, _yawlServiceID=TEST3}
DEBUG - au.edu.qut.yawl.elements.YAWLServiceReference{_documentation=null, _yawlServiceID=TEST2}
DEBUG - au.edu.qut.yawl.elements.YAWLServiceReference{_documentation=null, _yawlServiceID=TEST1}
DEBUG - executing flush
DEBUG - Inserting entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST1]
DEBUG - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG - insert into services (documentation, serviceid) values (?, ?)
Hibernate: insert into services (documentation, serviceid) values (?, ?)
DEBUG - preparing statement
DEBUG - Dehydrating entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST1]
DEBUG - binding null to parameter: 1
DEBUG - binding 'TEST1' to parameter: 2
DEBUG - Inserting entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST2]
DEBUG - Dehydrating entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST2]
DEBUG - binding null to parameter: 1
DEBUG - binding 'TEST2' to parameter: 2
DEBUG - Inserting entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST3]
DEBUG - Dehydrating entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST3]
DEBUG - binding null to parameter: 1
DEBUG - binding 'TEST3' to parameter: 2
DEBUG - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG - closing statement
DEBUG - post flush
[color=red]DEBUG - transaction completion
DEBUG - closing session
DEBUG - disconnecting session
DEBUG - returning connection to pool, pool size: 1
DEBUG - transaction completion
DEBUG - opened session
DEBUG - begin
DEBUG - current autocommit status:false[/color]
DEBUG - generated identifier: TEST4
DEBUG - saving [au.edu.qut.yawl.elements.YAWLServiceReference#TEST4]
DEBUG - generated identifier: TEST5
DEBUG - saving [au.edu.qut.yawl.elements.YAWLServiceReference#TEST5]
DEBUG - generated identifier: TEST6
DEBUG - saving [au.edu.qut.yawl.elements.YAWLServiceReference#TEST6]
DEBUG - commit
DEBUG - flushing session
DEBUG - Flushing entities and processing referenced collections
DEBUG - Processing unreferenced collections
DEBUG - Scheduling collection removes/(re)creates/updates
DEBUG - Flushed: 3 insertions, 0 updates, 0 deletions to 3 objects
DEBUG - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG - listing entities:
DEBUG - au.edu.qut.yawl.elements.YAWLServiceReference{_documentation=null, _yawlServiceID=TEST5}
DEBUG - au.edu.qut.yawl.elements.YAWLServiceReference{_documentation=null, _yawlServiceID=TEST6}
DEBUG - au.edu.qut.yawl.elements.YAWLServiceReference{_documentation=null, _yawlServiceID=TEST4}
DEBUG - executing flush
DEBUG - Inserting entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST4]
DEBUG - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG - insert into services (documentation, serviceid) values (?, ?)
Hibernate: insert into services (documentation, serviceid) values (?, ?)
DEBUG - preparing statement
DEBUG - Dehydrating entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST4]
DEBUG - binding null to parameter: 1
DEBUG - binding 'TEST4' to parameter: 2
DEBUG - Inserting entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST5]
DEBUG - Dehydrating entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST5]
DEBUG - binding null to parameter: 1
DEBUG - binding 'TEST5' to parameter: 2
DEBUG - Inserting entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST6]
DEBUG - Dehydrating entity: [au.edu.qut.yawl.elements.YAWLServiceReference#TEST6]
DEBUG - binding null to parameter: 1
DEBUG - binding 'TEST6' to parameter: 2
DEBUG - done closing: 0 open PreparedStatements, 0 open ResultSets
[color=red]DEBUG - closing statement
DEBUG - post flush
DEBUG - transaction completion
DEBUG - closing session
DEBUG - disconnecting session
DEBUG - transaction completion[/color]
Process finished with exit code 0
Code: