-->
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.  [ 7 posts ] 
Author Message
 Post subject: Why Hibernate don't save an object to MySQL database.
PostPosted: Sun Apr 16, 2006 11:29 am 
Newbie

Joined: Sun Apr 16, 2006 10:18 am
Posts: 3
I have the following problem. Hibernate do't want to save objects to MySQL DB.

Hibernate version:
version 3.1.3

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.sum">
<class name="Event" table="users">
<id name="id" column="uid">
<generator class="native"/>
</id>
<property name="fname" type="string" column="fname"/>
<property name="lname" type="string" column="lname"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Configuration cfg=new Configuration();
Session session=null;
try
{
SessionFactory factory=cfg.configure().buildSessionFactory();

Event theEvent=new Event();
theEvent.setFname("Devid");
theEvent.setLname("Backham");

session=factory.openSession();

session.save(theEvent);

}
catch (Exception e)
{
System.out.println(e);
}
finally
{
factory.close();
session.flush();
session.close();
}


Name and version of the database you are using:
MySQL version 4.1.13a-nt


Debug level Hibernate log excerpt:
2006-04-16 18:10:18,796 INFO Environment: - Hibernate 3.1.3
2006-04-16 18:10:18,843 INFO Environment: - hibernate.properties not found
2006-04-16 18:10:18,843 INFO Environment: - using CGLIB reflection optimizer
2006-04-16 18:10:18,843 INFO Environment: - using JDK 1.4 java.sql.Timestamp handling
2006-04-16 18:10:19,390 INFO Configuration: - configuring from resource: /hibernate.cfg.xml
2006-04-16 18:10:19,390 INFO Configuration: - Configuration resource: /hibernate.cfg.xml
2006-04-16 18:10:21,031 DEBUG DTDEntityResolver: - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
2006-04-16 18:10:21,031 DEBUG DTDEntityResolver: - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
2006-04-16 18:10:21,031 DEBUG DTDEntityResolver: - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
2006-04-16 18:10:21,218 DEBUG Configuration: - connection.driver_class=com.mysql.jdbc.Driver
2006-04-16 18:10:21,234 DEBUG Configuration: - connection.url=jdbc:mysql://localhost/mydb
2006-04-16 18:10:21,234 DEBUG Configuration: - connection.username=root
2006-04-16 18:10:21,234 DEBUG Configuration: - connection.password=myname_yuri
2006-04-16 18:10:21,234 DEBUG Configuration: - dialect=org.hibernate.dialect.MySQLDialect
2006-04-16 18:10:21,234 DEBUG Configuration: - show_sql=true
2006-04-16 18:10:21,234 DEBUG Configuration: - null<-org.dom4j.tree.DefaultAttribute@13ad33d [Attribute: name resource value "com/sum/Event.hbm.xml"]
2006-04-16 18:10:21,234 INFO Configuration: - Reading mappings from resource: com/sum/Event.hbm.xml
2006-04-16 18:10:21,234 DEBUG DTDEntityResolver: - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd]
2006-04-16 18:10:21,234 DEBUG DTDEntityResolver: - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
2006-04-16 18:10:21,234 DEBUG DTDEntityResolver: - located [http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd] in classpath
2006-04-16 18:10:21,750 INFO HbmBinder: - Mapping class: com.sum.Event -> users
2006-04-16 18:10:21,859 DEBUG HbmBinder: - Mapped property: id -> uid
2006-04-16 18:10:21,968 DEBUG HbmBinder: - Mapped property: fname -> fname
2006-04-16 18:10:21,968 DEBUG HbmBinder: - Mapped property: lname -> lname
2006-04-16 18:10:21,968 INFO Configuration: - Configured SessionFactory: null
2006-04-16 18:10:21,968 DEBUG Configuration: - properties: {hibernate.connection.password=myname_yuri, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=F:\j2sdk_5_0\jre\bin, java.vm.version=1.5.0-b64, hibernate.connection.username=root, ant.library.dir=F:\JavaFWrk\apache-ant-1.6.5\lib, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=RU, sun.os.patch.level=Service Pack 4, java.vm.specification.name=Java Virtual Machine Specification, user.dir=F:\java_projects\work\MyApp1_14_04_2006, java.runtime.version=1.5.0-b64, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=F:\j2sdk_5_0\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=F:\DOCUME~1\9335~1\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows 2000, ant.home=F:\JavaFWrk\apache-ant-1.6.5, sun.jnu.encoding=Cp1251, java.library.path=F:\j2sdk_5_0\bin;.;F:\WINNT\system32;F:\Documents and Settings\А.м.н.стратор\WINDOWS;F:\Oracle\Ora81\bin;F:\PROGRA~1\Borland\Delphi5\Projects\Bpl;F:\PROGRA~1\Borland\vbroker\Bin;F:\PROGRA~1\Borland\Delphi5\Bin;F:\WINNT\system32;F:\WINNT;F:\WINNT\System32\Wbem;F:\PROGRA~1\MICROS~3\Office;F:\Program Files\Microsoft SQL Server\80\Tools\BINN;F:\Program Files\ATI Technologies\ATI Control Panel;F:\j2sdk_5_0\bin;G:\MySQL_4_1\bin;F:\Program Files\Intel\DMIX;F:\JavaFWrk\apache-ant-1.6.5\bin;F:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;F:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;F:\Program Files\Microsoft Visual Studio\Common\Tools;F:\Program Files\Microsoft Visual Studio\VC98\bin;F:\j2sdk_5_0\bin;;C:\PROGRA~1\ATITEC~1\ATICON~1, java.specification.name=Java Platform API Specification, java.class.version=49.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.0, connection.password=myname_yuri, user.home=F:\Documents and Settings\А.м.н.стратор, user.timezone=Europe/Athens, connection.username=root, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1251, java.specification.version=1.5, hibernate.connection.driver_class=com.mysql.jdbc.Driver, show_sql=true, java.class.path=F:\JavaFWrk\apache-ant-1.6.5\lib\ant-launcher.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-antlr.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-bcel.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-bsf.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-log4j.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-oro.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-regexp.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-resolver.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-commons-logging.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-commons-net.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-icontract.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-jai.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-javamail.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-jdepend.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-jmf.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-jsch.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-junit.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-launcher.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-netrexx.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-nodeps.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-starteam.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-stylebook.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-swing.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-trax.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-vaj.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-weblogic.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-xalan1.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-xslp.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\xercesImpl.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\xml-apis.jar;F:\j2sdk_5_0\lib\tools.jar, user.name=А.м.н.стратор, hibernate.show_sql=true, java.vm.specification.version=1.0, java.home=F:\j2sdk_5_0\jre, sun.arch.data.model=32, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost/mydb, user.language=ru, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, sharing, java.version=1.5.0, java.ext.dirs=F:\j2sdk_5_0\jre\lib\ext, sun.boot.class.path=F:\j2sdk_5_0\jre\lib\rt.jar;F:\j2sdk_5_0\jre\lib\i18n.jar;F:\j2sdk_5_0\jre\lib\sunrsasign.jar;F:\j2sdk_5_0\jre\lib\jsse.jar;F:\j2sdk_5_0\jre\lib\jce.jar;F:\j2sdk_5_0\jre\lib\charsets.jar;F:\j2sdk_5_0\jre\classes, java.vendor=Sun Microsystems Inc., connection.driver_class=com.mysql.jdbc.Driver, file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.desktop=windows, connection.url=jdbc:mysql://localhost/mydb, dialect=org.hibernate.dialect.MySQLDialect, sun.cpu.isalist=}
2006-04-16 18:10:21,968 DEBUG Configuration: - Preparing to build session factory with filters : {}
2006-04-16 18:10:21,968 DEBUG Configuration: - processing extends queue
2006-04-16 18:10:21,968 DEBUG Configuration: - processing collection mappings
2006-04-16 18:10:21,984 DEBUG Configuration: - processing native query and ResultSetMapping mappings
2006-04-16 18:10:21,984 DEBUG Configuration: - processing association property references
2006-04-16 18:10:21,984 DEBUG Configuration: - processing foreign key constraints
2006-04-16 18:10:22,468 INFO DriverManagerConnectionProvider: - Using Hibernate built-in connection pool (not for production use!)
2006-04-16 18:10:22,484 INFO DriverManagerConnectionProvider: - Hibernate connection pool size: 20
2006-04-16 18:10:22,484 INFO DriverManagerConnectionProvider: - autocommit mode: false
2006-04-16 18:10:22,500 INFO DriverManagerConnectionProvider: - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/mydb
2006-04-16 18:10:22,500 INFO DriverManagerConnectionProvider: - connection properties: {user=root, password=myname_yuri}
2006-04-16 18:10:22,500 DEBUG DriverManagerConnectionProvider: - total checked-out connections: 0
2006-04-16 18:10:22,500 DEBUG DriverManagerConnectionProvider: - opening new JDBC connection
2006-04-16 18:10:23,515 DEBUG DriverManagerConnectionProvider: - created connection to: jdbc:mysql://localhost/mydb, Isolation Level: 4
2006-04-16 18:10:23,515 INFO SettingsFactory: - RDBMS: MySQL, version: 4.1.13a-nt
2006-04-16 18:10:23,515 INFO SettingsFactory: - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
2006-04-16 18:10:23,515 DEBUG DriverManagerConnectionProvider: - returning connection to pool, pool size: 1
2006-04-16 18:10:23,656 INFO Dialect: - Using dialect: org.hibernate.dialect.MySQLDialect
2006-04-16 18:10:23,687 INFO TransactionFactoryFactory: - Using default transaction strategy (direct JDBC transactions)
2006-04-16 18:10:23,718 INFO TransactionManagerLookupFactory: - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2006-04-16 18:10:23,718 INFO SettingsFactory: - Automatic flush during beforeCompletion(): disabled
2006-04-16 18:10:23,718 INFO SettingsFactory: - Automatic session close at end of transaction: disabled
2006-04-16 18:10:23,718 INFO SettingsFactory: - JDBC batch size: 15
2006-04-16 18:10:23,718 INFO SettingsFactory: - JDBC batch updates for versioned data: disabled
2006-04-16 18:10:23,734 INFO SettingsFactory: - Scrollable result sets: enabled
2006-04-16 18:10:23,734 DEBUG SettingsFactory: - Wrap result sets: disabled
2006-04-16 18:10:23,734 INFO SettingsFactory: - JDBC3 getGeneratedKeys(): enabled
2006-04-16 18:10:23,734 INFO SettingsFactory: - Connection release mode: auto
2006-04-16 18:10:23,734 INFO SettingsFactory: - Maximum outer join fetch depth: 2
2006-04-16 18:10:23,734 INFO SettingsFactory: - Default batch fetch size: 1
2006-04-16 18:10:23,734 INFO SettingsFactory: - Generate SQL with comments: disabled
2006-04-16 18:10:23,734 INFO SettingsFactory: - Order SQL updates by primary key: disabled
2006-04-16 18:10:23,734 INFO SettingsFactory: - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2006-04-16 18:10:23,765 INFO ASTQueryTranslatorFactory: - Using ASTQueryTranslatorFactory
2006-04-16 18:10:23,765 INFO SettingsFactory: - Query language substitutions: {}
2006-04-16 18:10:23,765 INFO SettingsFactory: - Second-level cache: enabled
2006-04-16 18:10:23,765 INFO SettingsFactory: - Query cache: disabled
2006-04-16 18:10:23,765 INFO SettingsFactory: - Cache provider: org.hibernate.cache.EhCacheProvider
2006-04-16 18:10:23,796 INFO SettingsFactory: - Optimize cache for minimal puts: disabled
2006-04-16 18:10:23,796 INFO SettingsFactory: - Structured second-level cache entries: disabled
2006-04-16 18:10:23,796 DEBUG SQLExceptionConverterFactory: - Using dialect defined converter
2006-04-16 18:10:23,843 INFO SettingsFactory: - Echoing all SQL to stdout
2006-04-16 18:10:23,843 INFO SettingsFactory: - Statistics: disabled
2006-04-16 18:10:23,843 INFO SettingsFactory: - Deleted entity synthetic identifier rollback: disabled
2006-04-16 18:10:23,843 INFO SettingsFactory: - Default entity-mode: pojo
2006-04-16 18:10:41,078 INFO SessionFactoryImpl: - building session factory
2006-04-16 18:10:41,078 DEBUG SessionFactoryImpl: - Session factory constructed with filter configurations : {}
2006-04-16 18:10:41,078 DEBUG SessionFactoryImpl: - instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=myname_yuri, sun.boot.library.path=F:\j2sdk_5_0\jre\bin, java.vm.version=1.5.0-b64, ant.library.dir=F:\JavaFWrk\apache-ant-1.6.5\lib, hibernate.connection.username=root, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=RU, sun.os.patch.level=Service Pack 4, java.vm.specification.name=Java Virtual Machine Specification, user.dir=F:\java_projects\work\MyApp1_14_04_2006, java.runtime.version=1.5.0-b64, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=F:\j2sdk_5_0\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=F:\DOCUME~1\9335~1\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows 2000, ant.home=F:\JavaFWrk\apache-ant-1.6.5, sun.jnu.encoding=Cp1251, java.library.path=F:\j2sdk_5_0\bin;.;F:\WINNT\system32;F:\Documents and Settings\А.м.н.стратор\WINDOWS;F:\Oracle\Ora81\bin;F:\PROGRA~1\Borland\Delphi5\Projects\Bpl;F:\PROGRA~1\Borland\vbroker\Bin;F:\PROGRA~1\Borland\Delphi5\Bin;F:\WINNT\system32;F:\WINNT;F:\WINNT\System32\Wbem;F:\PROGRA~1\MICROS~3\Office;F:\Program Files\Microsoft SQL Server\80\Tools\BINN;F:\Program Files\ATI Technologies\ATI Control Panel;F:\j2sdk_5_0\bin;G:\MySQL_4_1\bin;F:\Program Files\Intel\DMIX;F:\JavaFWrk\apache-ant-1.6.5\bin;F:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;F:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;F:\Program Files\Microsoft Visual Studio\Common\Tools;F:\Program Files\Microsoft Visual Studio\VC98\bin;F:\j2sdk_5_0\bin;;C:\PROGRA~1\ATITEC~1\ATICON~1, java.specification.name=Java Platform API Specification, java.class.version=49.0, sun.management.compiler=HotSpot Client Compiler, os.version=5.0, user.home=F:\Documents and Settings\А.м.н.стратор, connection.password=myname_yuri, user.timezone=Europe/Athens, java.awt.printerjob=sun.awt.windows.WPrinterJob, connection.username=root, java.specification.version=1.5, file.encoding=Cp1251, hibernate.connection.driver_class=com.mysql.jdbc.Driver, show_sql=true, user.name=А.м.н.стратор, java.class.path=F:\JavaFWrk\apache-ant-1.6.5\lib\ant-launcher.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-antlr.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-bcel.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-bsf.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-log4j.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-oro.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-regexp.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-apache-resolver.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-commons-logging.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-commons-net.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-icontract.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-jai.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-javamail.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-jdepend.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-jmf.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-jsch.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-junit.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-launcher.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-netrexx.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-nodeps.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-starteam.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-stylebook.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-swing.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-trax.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-vaj.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-weblogic.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-xalan1.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant-xslp.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\ant.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\xercesImpl.jar;F:\JavaFWrk\apache-ant-1.6.5\lib\xml-apis.jar;F:\j2sdk_5_0\lib\tools.jar, hibernate.show_sql=true, java.vm.specification.version=1.0, sun.arch.data.model=32, java.home=F:\j2sdk_5_0\jre, hibernate.connection.url=jdbc:mysql://localhost/mydb, hibernate.dialect=org.hibernate.dialect.MySQLDialect, java.specification.vendor=Sun Microsystems Inc., user.language=ru, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, sharing, hibernate.cglib.use_reflection_optimizer=true, java.version=1.5.0, java.ext.dirs=F:\j2sdk_5_0\jre\lib\ext, sun.boot.class.path=F:\j2sdk_5_0\jre\lib\rt.jar;F:\j2sdk_5_0\jre\lib\i18n.jar;F:\j2sdk_5_0\jre\lib\sunrsasign.jar;F:\j2sdk_5_0\jre\lib\jsse.jar;F:\j2sdk_5_0\jre\lib\jce.jar;F:\j2sdk_5_0\jre\lib\charsets.jar;F:\j2sdk_5_0\jre\classes, java.vendor=Sun Microsystems Inc., file.separator=\, connection.driver_class=com.mysql.jdbc.Driver, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.cpu.endian=little, sun.io.unicode.encoding=UnicodeLittle, sun.desktop=windows, connection.url=jdbc:mysql://localhost/mydb, sun.cpu.isalist=, dialect=org.hibernate.dialect.MySQLDialect}
2006-04-16 18:10:41,093 DEBUG CacheManager: - Creating new CacheManager with default config
2006-04-16 18:10:41,125 DEBUG CacheManager: - Configuring ehcache from classpath.
2006-04-16 18:10:41,156 WARN Configurator: - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/F:/java_projects/work/MyApp1_14_04_2006/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
2006-04-16 18:10:41,203 DEBUG Configuration$DiskStore: - Disk Store Path: F:\DOCUME~1\9335~1\LOCALS~1\Temp\
2006-04-16 18:10:42,953 DEBUG AbstractEntityPersister: - Static SQL for entity: com.sum.Event
2006-04-16 18:10:42,953 DEBUG AbstractEntityPersister: - Version select: select uid from users where uid =?
2006-04-16 18:10:42,953 DEBUG AbstractEntityPersister: - Snapshot select: select event_.uid, event_.fname as fname0_, event_.lname as lname0_ from users event_ where event_.uid=?
2006-04-16 18:10:42,953 DEBUG AbstractEntityPersister: - Insert 0: insert into users (fname, lname, uid) values (?, ?, ?)
2006-04-16 18:10:42,953 DEBUG AbstractEntityPersister: - Update 0: update users set fname=?, lname=? where uid=?
2006-04-16 18:10:42,953 DEBUG AbstractEntityPersister: - Delete 0: delete from users where uid=?
2006-04-16 18:10:42,953 DEBUG AbstractEntityPersister: - Identity insert: insert into users (fname, lname) values (?, ?)
2006-04-16 18:10:43,078 DEBUG EntityLoader: - Static select for entity com.sum.Event: select event0_.uid as uid0_0_, event0_.fname as fname0_0_, event0_.lname as lname0_0_ from users event0_ where event0_.uid=?
2006-04-16 18:10:43,078 DEBUG EntityLoader: - Static select for entity com.sum.Event: select event0_.uid as uid0_0_, event0_.fname as fname0_0_, event0_.lname as lname0_0_ from users event0_ where event0_.uid=?
2006-04-16 18:10:43,078 DEBUG EntityLoader: - Static select for entity com.sum.Event: select event0_.uid as uid0_0_, event0_.fname as fname0_0_, event0_.lname as lname0_0_ from users event0_ where event0_.uid=? for update
2006-04-16 18:10:43,078 DEBUG EntityLoader: - Static select for entity com.sum.Event: select event0_.uid as uid0_0_, event0_.fname as fname0_0_, event0_.lname as lname0_0_ from users event0_ where event0_.uid=? for update
2006-04-16 18:10:43,171 DEBUG EntityLoader: - Static select for action ACTION_MERGE on entity com.sum.Event: select event0_.uid as uid0_0_, event0_.fname as fname0_0_, event0_.lname as lname0_0_ from users event0_ where event0_.uid=?
2006-04-16 18:10:43,171 DEBUG EntityLoader: - Static select for action ACTION_REFRESH on entity com.sum.Event: select event0_.uid as uid0_0_, event0_.fname as fname0_0_, event0_.lname as lname0_0_ from users event0_ where event0_.uid=?
2006-04-16 18:10:43,171 DEBUG SessionFactoryObjectFactory: - initializing class SessionFactoryObjectFactory
2006-04-16 18:10:43,187 DEBUG SessionFactoryObjectFactory: - registered: 402880ce0aa340e9010aa340f1e30000 (unnamed)
2006-04-16 18:10:43,187 INFO SessionFactoryObjectFactory: - Not binding factory to JNDI, no JNDI name configured
2006-04-16 18:10:43,187 DEBUG SessionFactoryImpl: - instantiated session factory
2006-04-16 18:10:43,187 DEBUG SessionFactoryImpl: - Checking 0 named HQL queries
2006-04-16 18:10:43,187 DEBUG SessionFactoryImpl: - Checking 0 named SQL queries
2006-04-16 18:10:43,468 DEBUG SessionImpl: - opened session at timestamp: 4690740196159488
2006-04-16 18:10:43,500 DEBUG DefaultSaveOrUpdateEventListener: - saving transient instance
2006-04-16 18:10:43,500 DEBUG AbstractSaveEventListener: - saving [com.sum.Event#<null>]
2006-04-16 18:10:43,500 DEBUG AbstractSaveEventListener: - executing insertions
2006-04-16 18:10:43,593 DEBUG AbstractEntityPersister: - Inserting entity: com.sum.Event (native id)
2006-04-16 18:10:43,593 DEBUG AbstractBatcher: - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-04-16 18:10:43,593 DEBUG ConnectionManager: - opening JDBC connection
2006-04-16 18:10:43,593 DEBUG DriverManagerConnectionProvider: - total checked-out connections: 0
2006-04-16 18:10:43,593 DEBUG DriverManagerConnectionProvider: - using pooled JDBC connection, pool size: 0
2006-04-16 18:10:43,593 DEBUG SQL: - insert into users (fname, lname) values (?, ?)
2006-04-16 18:10:43,593 DEBUG AbstractBatcher: - preparing statement
2006-04-16 18:10:43,640 DEBUG AbstractEntityPersister: - Dehydrating entity: [com.sum.Event#<null>]
2006-04-16 18:10:43,640 DEBUG StringType: - binding 'Devid' to parameter: 1
2006-04-16 18:10:43,640 DEBUG StringType: - binding 'Backham' to parameter: 2
2006-04-16 18:10:43,640 DEBUG IdentifierGeneratorFactory: - Natively generated identity: 9
2006-04-16 18:10:43,640 DEBUG AbstractBatcher: - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-04-16 18:10:43,640 DEBUG AbstractBatcher: - closing statement
2006-04-16 18:10:43,671 INFO SessionFactoryImpl: - closing
2006-04-16 18:10:43,671 INFO DriverManagerConnectionProvider: - cleaning up connection pool: jdbc:mysql://localhost/mydb
2006-04-16 18:10:43,671 DEBUG AbstractFlushingEventListener: - flushing session
2006-04-16 18:10:43,671 DEBUG AbstractFlushingEventListener: - processing flush-time cascades
2006-04-16 18:10:43,671 DEBUG AbstractFlushingEventListener: - dirty checking collections
2006-04-16 18:10:43,671 DEBUG AbstractFlushingEventListener: - Flushing entities and processing referenced collections
2006-04-16 18:10:43,703 DEBUG AbstractFlushingEventListener: - Processing unreferenced collections
2006-04-16 18:10:43,703 DEBUG AbstractFlushingEventListener: - Scheduling collection removes/(re)creates/updates
2006-04-16 18:10:43,703 DEBUG AbstractFlushingEventListener: - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
2006-04-16 18:10:43,703 DEBUG AbstractFlushingEventListener: - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2006-04-16 18:10:43,718 DEBUG Printer: - listing entities:
2006-04-16 18:10:43,718 DEBUG Printer: - com.sum.Event{lname=Backham, fname=Devid, id=9}
2006-04-16 18:10:43,718 DEBUG AbstractFlushingEventListener: - executing flush
2006-04-16 18:10:43,718 DEBUG ConnectionManager: - registering flush begin
2006-04-16 18:10:43,718 DEBUG ConnectionManager: - registering flush end
2006-04-16 18:10:43,718 DEBUG AbstractFlushingEventListener: - post flush
2006-04-16 18:10:43,718 DEBUG SessionImpl: - closing session
2006-04-16 18:10:43,718 DEBUG ConnectionManager: - performing cleanup
2006-04-16 18:10:43,718 DEBUG ConnectionManager: - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2006-04-16 18:10:43,734 DEBUG DriverManagerConnectionProvider: - returning connection to pool, pool size: 1
2006-04-16 18:10:43,734 DEBUG JDBCContext: - after transaction completion
2006-04-16 18:10:43,734 DEBUG ConnectionManager: - aggressively releasing JDBC connection
2006-04-16 18:10:43,734 DEBUG SessionImpl: - after transaction completion

After that i try to test my MySQL table

SELECT * FROM users.

Server give the following message:
Table Empty.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 16, 2006 9:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Use transactions, use Innodb tables.
See Session API doc (or the reference docs) for the base transaction idiom.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 17, 2006 6:26 am 
Newbie

Joined: Sun Apr 16, 2006 10:18 am
Posts: 3
david wrote:
Use transactions, use Innodb tables.
See Session API doc (or the reference docs) for the base transaction idiom.


Why I mast use transaction. I read a lot of documentation and there no necessarily use of transactions.
For example:
(Hibernate Quickly:Patrick Peak, Nick Heudecker)

page # 68___________________________________________
Persisting a transient object with Hibernate is as simple as saving it
with the Session instance:
Event event = new Event();
// populate the event
Session session = factory.openSession();
session.save(event);
session.flush();
Calling save(...) for the Event instance assigns a generated ID value
to the instance and persists the instance. (Keep in mind that Hibernate
doesn’t set the ID value if the generator type is assigned.) The flush()
call forces persistent objects held in memory to be synchronized to the
database. Sessions don’t immediately write to the database when an
object is saved. Instead, the Session queues a number of database
writes to maximize performance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 17, 2006 8:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have not read the book so I cannot judge what has been said. I suggest you get HIA (or the followup book once it is out). Getting back to the point, you do need transactions it is fundamental to how your database works. So here is the idiom you should be using.

Code:
Session sess = factory.openSession();
Transaction tx;
try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
}
catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
}
finally {
     sess.close();
}


Sometimes code is used that hides the presence of the transactional operations - this can be confusing for some users. Various examples are on the Wiki. For now I suggest you apply the above code and see how you go.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 9:03 am 
Newbie

Joined: Sun Apr 16, 2006 10:18 am
Posts: 3
Thank you david. Certainly the code with transactons work correctly and i use this variant. But it will be rather bette fo me if you can tell me in detail why using only save and flush methods do't work.

And one more question:
insert into TABLENAME (COLUMN_01, COLUMN_02, COLUMN_03) values (?, ?, ?)
While hibernate show Question mark instead of real data.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 3:43 pm 
Newbie

Joined: Wed Apr 05, 2006 5:27 pm
Posts: 6
Location: SP - BR
Hi Yuri,

About your question, flush method syncronize the JDBC connection's state with the state of objects held in memory. Usually, flush occurs by default at the following points :

- Before some query executions;
- from org.hibernate.Transaction.commit();
- from Session.flush().

So, if you called session.getTransaction().commit() after the process, you don't need to call the session.flush().

Did you ask for more details about use of save or flush :

Code:
public static void main(String[] args) {
        Session session = null;
        Transaction transaction = null;
       
        try {
            // Get a Session instance
            session = HibernateUtil.getSession();
            // Get a transaction
            transaction = session.beginTransaction();
           
            // Find a object entity Empresa
            Empresa e = (Empresa) session.get(Empresa.class, new Long(15));
            // Find a object entity Pagamento
            Pagamento p = (Pagamento) session.get(Pagamento.class, new Long(4));
                       
            // Instance of PK
            EmpresaPagamentoPK pk = new EmpresaPagamentoPK();
            pk.setEmpresa(e);
            pk.setPagamento(p);
            EmpresaPagamento ep = new EmpresaPagamento();
            ep.setId(pk);
           
            // Save the object
            session.saveOrUpdate(ep);
        } catch (Exception e) {
            // Rollback transaction
            transaction.rollback();
        }
        finally {
            // Requirid commit transaction
            transaction.commit(); // don't need to call flush()
            // Close session
            session.close();
        }
    }


Another example :

When making new objects persistent, you must flush() and then clear() the session regularly, to control the
size of the first-level cache.

Code:
     Session session = sessionFactory.openSession();
     Transaction tx = session.beginTransaction();
     for ( int i=0; i<100000; i++ ) {
          Customer customer = new Customer(.....);
          session.save(customer);
          if ( i % 20 == 0 ) { //20, same as the JDBC batch size
               //flush a batch of inserts and release memory:
               session.flush();
               session.clear();
          }
     }
     tx.commit();
     session.close();


Quote:
And one more question:
insert into TABLENAME (COLUMN_01, COLUMN_02, COLUMN_03) values (?, ?, ?)
While hibernate show Question mark instead of real data.


Hibernate use java.sql.PreparedStatement to persist the objects, so, in the transaction, the 'Question mark' will be substitute for real datas.
See more details in : http://java.sun.com/j2se/1.5.0/docs/api ... ement.html

Regards

_________________
Márcio Alves Barroso


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 7:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Thank you Marcio for helping out.
Yuri hope this has answered your questions.

Please remember to mark helpful answers as a reward to those answering questions just as Marcio has.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.