-->
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: Saving with no transaction...
PostPosted: Thu Feb 10, 2005 4:05 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
Hi ng,

This is a simple question but one that i have been unable to find a clear answer for (it could be that i have configured something incorrectly ot that my db dosen't support it). Basically i was hoping someone could tell me if it is a requirement that you can only insert objects to a database within a transaction? btw i'm using oracle 9i.

thanks,
cam

The following will not persist to the db:

Code:
public class TestClass  {

    private Long id;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}


Code:
        try {
            Configuration config = new Configuration();
            config.addClass(TestClass.class);

            SessionFactory fac = config.buildSessionFactory();
            Session s = fac.openSession();
            s.save(new TestClass());
            s.flush();
            s.close();
        } catch (HibernateException e) {
            e.printStackTrace();
        }



Code:
<hibernate-mapping>
   <class name="test.TestClass" table="TestClass">
      <id type="long" name="id" length="8">
         <generator class="native"/>
      </id>
   </class>
</hibernate-mapping>


Code:
2005-02-10 18:44:09,906 INFO net.sf.hibernate.cfg.Environment - Hibernate 2.1.5
2005-02-10 18:44:09,906 INFO net.sf.hibernate.cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.transaction.flush_before_completion=, hibernate.connection.autocommit=true, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.connection.username=XXXXXX, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:oracle:thin:@XXXXXX:1521:Test, hibernate.show_sql=true, hibernate.connection.password=password, hibernate.connection.pool_size=1}
2005-02-10 18:44:09,921 INFO net.sf.hibernate.cfg.Environment - using java.io streams to persist binary types
2005-02-10 18:44:09,921 INFO net.sf.hibernate.cfg.Environment - using CGLIB reflection optimizer
2005-02-10 18:44:09,921 INFO net.sf.hibernate.cfg.Configuration - Mapping resource: test/TestClass.hbm.xml
2005-02-10 18:44:10,062 DEBUG net.sf.hibernate.util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath under net/sf/hibernate/
2005-02-10 18:44:10,062 DEBUG net.sf.hibernate.util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd in classpath
2005-02-10 18:44:10,234 INFO net.sf.hibernate.cfg.Binder - Mapping class: au.com.sensis.bidsmart.business.campaign.TestClass -> TestClass
2005-02-10 18:44:10,328 DEBUG net.sf.hibernate.cfg.Binder - Mapped property: id -> id, type: long
2005-02-10 18:44:10,343 INFO net.sf.hibernate.cfg.Configuration - processing one-to-many association mappings
2005-02-10 18:44:10,343 INFO net.sf.hibernate.cfg.Configuration - processing one-to-one association property references
2005-02-10 18:44:10,343 INFO net.sf.hibernate.cfg.Configuration - processing foreign key constraints
2005-02-10 18:44:10,375 INFO net.sf.hibernate.dialect.Dialect - Using dialect: net.sf.hibernate.dialect.Oracle9Dialect
2005-02-10 18:44:10,375 INFO net.sf.hibernate.cfg.SettingsFactory - Maximim outer join fetch depth: 1
2005-02-10 18:44:10,375 INFO net.sf.hibernate.cfg.SettingsFactory - Use outer join fetching: true
2005-02-10 18:44:10,375 INFO net.sf.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
2005-02-10 18:44:10,375 INFO net.sf.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 1
2005-02-10 18:44:10,453 INFO net.sf.hibernate.connection.DriverManagerConnectionProvider - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@XXXXXX:1521:Test
2005-02-10 18:44:10,453 INFO net.sf.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=XXXXXX, password=password, autocommit=true}
2005-02-10 18:44:10,468 INFO net.sf.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
2005-02-10 18:44:10,468 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
2005-02-10 18:44:10,468 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - opening new JDBC connection
2005-02-10 18:44:10,984 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - created connection to: jdbc:oracle:thin:@XXXXXXX:1521:TEst, Isolation Level: 2
2005-02-10 18:44:11,031 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
2005-02-10 18:44:11,031 INFO net.sf.hibernate.cfg.SettingsFactory - Use scrollable result sets: true
2005-02-10 18:44:11,031 INFO net.sf.hibernate.cfg.SettingsFactory - Use JDBC3 getGeneratedKeys(): false
2005-02-10 18:44:11,031 INFO net.sf.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: false
2005-02-10 18:44:11,031 INFO net.sf.hibernate.cfg.SettingsFactory - echoing all SQL to stdout
2005-02-10 18:44:11,031 INFO net.sf.hibernate.cfg.SettingsFactory - Query language substitutions: {no='N', true=1, yes='Y', false=0}
2005-02-10 18:44:11,031 INFO net.sf.hibernate.cfg.SettingsFactory - cache provider: net.sf.hibernate.cache.HashtableCacheProvider
2005-02-10 18:44:11,031 INFO net.sf.hibernate.cfg.SettingsFactory - query cache factory: net.sf.hibernate.cache.StandardQueryCacheFactory
2005-02-10 18:44:11,031 INFO net.sf.hibernate.cfg.Configuration - instantiating and configuring caches
2005-02-10 18:44:11,187 INFO net.sf.hibernate.impl.SessionFactoryImpl - building session factory
2005-02-10 18:44:11,187 DEBUG net.sf.hibernate.impl.SessionFactoryImpl - instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=password, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, sun.boot.library.path=C:\j2sdk1.4.2\jre\bin, java.vm.version=1.4.2-b28, hibernate.connection.username=XXXXXX, 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, user.country=AU, sun.os.patch.level=Service Pack 1, java.vm.specification.name=Java Virtual Machine Specification, user.dir=D:\bidsmart\workspace\Getsmart, java.runtime.version=1.4.2-b28, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\j2sdk1.4.2\jre\lib\endorsed, os.arch=x86, hibernate.connection.autocommit=true, java.io.tmpdir=D:\DOCUME~1\w75878\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows XP, sun.java2d.fontpath=, hibernate.cache.region_prefix=hibernate.test, java.library.path=C:\j2sdk1.4.2\bin;.;C:\WINDOWS\System32;C:\WINDOWS;C:\Apps\Ora81X\Bin;C:\Program Files\Oracle\jre\1.1.7\Bin;C:\Apps\OraNt\Bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\system32\nls;C:\WINDOWS\system32\nls\ENGLISH;c:\Program Files\Novell\ZENworks\;C:\j2sdk1.4.2\bin;Z:., java.specification.name=Java Platform API Specification, java.class.version=48.0, hibernate.connection.pool_size=1, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.1, user.home=D:\Documents and Settings\XXXXXX, user.timezone=Australia/Sydney, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.4, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, java.class.path=XXXuser.name=XXXX, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.show_sql=true, java.vm.specification.version=1.0, java.home=C:\j2sdk1.4.2\jre, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.Oracle9Dialect, hibernate.connection.url=jdbc:oracle:thin:@XXXXX:1521:Test, 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.transaction.flush_before_completion=, hibernate.jdbc.use_streams_for_binary=true, java.version=1.4.2, java.ext.dirs=C:\j2sdk1.4.2\jre\lib\ext, sun.boot.class.path=C:\j2sdk1.4.2\jre\lib\rt.jar;C:\j2sdk1.4.2\jre\lib\i18n.jar;C:\j2sdk1.4.2\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2\jre\lib\jsse.jar;C:\j2sdk1.4.2\jre\lib\jce.jar;C:\j2sdk1.4.2\jre\lib\charsets.jar;C:\j2sdk1.4.2\jre\classes, java.vendor=Sun Microsystems Inc., hibernate.jdbc.batch_size=0, file.separator=\, 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}
2005-02-10 18:44:11,562 DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - initializing class SessionFactoryObjectFactory
2005-02-10 18:44:11,578 DEBUG net.sf.hibernate.impl.SessionFactoryObjectFactory - registered: 21f5972501fb39990101fb399b2a0000 (unnamed)
2005-02-10 18:44:11,578 INFO net.sf.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
2005-02-10 18:44:11,578 DEBUG net.sf.hibernate.impl.SessionFactoryImpl - instantiated session factory
2005-02-10 18:44:11,578 INFO net.sf.hibernate.cache.UpdateTimestampsCache - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
2005-02-10 18:44:11,578 INFO net.sf.hibernate.cache.StandardQueryCache - starting query cache at region: net.sf.hibernate.cache.StandardQueryCache
2005-02-10 18:44:11,734 DEBUG net.sf.hibernate.impl.SessionImpl - opened session
2005-02-10 18:44:11,734 DEBUG net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-02-10 18:44:11,734 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - total checked-out connections: 0
2005-02-10 18:44:11,734 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
2005-02-10 18:44:11,734 DEBUG net.sf.hibernate.SQL - select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
2005-02-10 18:44:11,734 DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
2005-02-10 18:44:11,796 DEBUG net.sf.hibernate.id.SequenceGenerator - Sequence identifier generated: 2
2005-02-10 18:44:11,796 DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-02-10 18:44:11,796 DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
2005-02-10 18:44:11,796 DEBUG net.sf.hibernate.impl.SessionImpl - generated identifier: 2
2005-02-10 18:44:11,796 DEBUG net.sf.hibernate.impl.SessionImpl - saving [au.com.sensis.bidsmart.business.campaign.TestClass#2]
2005-02-10 18:44:11,812 DEBUG net.sf.hibernate.impl.SessionImpl - flushing session
2005-02-10 18:44:11,812 DEBUG net.sf.hibernate.impl.SessionImpl - Flushing entities and processing referenced collections
2005-02-10 18:44:11,812 DEBUG net.sf.hibernate.impl.SessionImpl - Processing unreferenced collections
2005-02-10 18:44:11,812 DEBUG net.sf.hibernate.impl.SessionImpl - Scheduling collection removes/(re)creates/updates
2005-02-10 18:44:11,812 DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
2005-02-10 18:44:11,812 DEBUG net.sf.hibernate.impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.Printer - listing entities:
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.Printer - au.com.sensis.bidsmart.business.campaign.TestClass{id=2}
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.SessionImpl - executing flush
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.persister.EntityPersister - Inserting entity: [test.TestClass#2]
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.SQL - insert into TestClass (id) values (?)
Hibernate: insert into TestClass (id) values (?)
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.persister.EntityPersister - Dehydrating entity: [test.TestClass#2]
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.type.LongType - binding '2' to parameter: 1
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.SessionImpl - post flush
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.SessionImpl - closing session
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.SessionImpl - disconnecting session
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.impl.SessionImpl - transaction completion
2005-02-10 18:44:11,828 DEBUG net.sf.hibernate.cache.UpdateTimestampsCache - Invalidating space [TestClass]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 10, 2005 8:37 am 
Newbie

Joined: Wed Jan 12, 2005 1:11 pm
Posts: 4
Location: London
Hi Cam,

It looks to me that it did persist the object, but as there was no transaction, commit was not called and hence it appears as though it wasn't persisted. If you really don't want to use transactions, then set auto-commit to true (session.getConnection().setAutoCommit(true) ). Obviously you run the risk of data inconsistency problems if you take that approach though.

chris


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.