I have one Parent (id,name) table and one Child(childId,childName,parentId(FK to id of Parent)) table.
I am trying to create a parent and hibernate generates insert query for Parent table and update query for Child table. My problem is that it isnt generating insert statement for Child table which thorws the following stack trace :
15:40:04,945 INFO Configuration:283 - Mapping resource: com/bunge/bgm/common/domain/user/Parent.hbm.xml
15:40:05,429 DEBUG DTDEntityResolver:20 - trying to locate
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
15:40:05,429 DEBUG DTDEntityResolver:29 - found
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
15:40:05,601 INFO Binder:178 - Mapping class: com.bunge.bgm.common.domain.user.Parent -> T_PARENT
15:40:05,695 DEBUG Binder:394 - Mapped property: _id -> ID, type: integer
15:40:05,726 DEBUG Binder:394 - Mapped property: _name -> NAME, type: string
15:40:05,742 DEBUG Binder:394 - Mapped property: _child, type: java.util.Collection
15:40:05,742 INFO Configuration:283 - Mapping resource: com/bunge/bgm/common/domain/user/Child.hbm.xml
15:40:05,742 DEBUG DTDEntityResolver:20 - trying to locate
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
15:40:05,757 DEBUG DTDEntityResolver:29 - found
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
15:40:05,789 INFO Binder:178 - Mapping class: com.bunge.bgm.common.domain.user.Child -> T_CHILD
15:40:05,789 DEBUG Binder:394 - Mapped property: _childId -> CHILD_ID, type: integer
15:40:05,789 DEBUG Binder:394 - Mapped property: _childName -> CHILD_NAME, type: string
15:40:05,789 DEBUG Binder:394 - Mapped property: _parent -> PARENT_ID, type: com.bunge.bgm.common.domain.user.Parent
15:40:05,789 INFO Configuration:492 - processing one-to-many association mappings
15:40:05,789 DEBUG Binder:1134 - Second pass for collection: com.bunge.bgm.common.domain.user.Parent._child
15:40:05,789 INFO Binder:1025 - Mapping collection: com.bunge.bgm.common.domain.user.Parent._child -> T_CHILD
15:40:05,789 DEBUG Binder:1146 - Mapped collection key: CHILD_ID, one-to-many: com.bunge.bgm.common.domain.user.Child
15:40:05,789 INFO Configuration:503 - processing foreign key constraints
15:40:05,789 DEBUG Configuration:513 - resolving reference to class: com.bunge.bgm.common.domain.user.Parent
15:40:06,007 INFO SessionFactoryImpl:132 - building session factory
15:40:06,007 DEBUG SessionFactoryImpl:134 - instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=BGM_CONTRACTS, sun.boot.library.path=C:\j2sdk1.4.2_01\jre\bin, java.vm.version=1.4.2_01-b06, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=BGM_CONTRACTS, 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=US, sun.os.patch.level=Service Pack 4, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\BGMIT\apps\Contract_Service, java.runtime.version=1.4.2_01-b06, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\j2sdk1.4.2_01\jre\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\crvashi\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows 2000, sun.java2d.fontpath=, java.library.path=C:\j2sdk1.4.2_01\jre\bin;.;C:\WINNT\system32;C:\WINNT;C:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\PROGRA~1\CA\Common\SCANEN~1;C:\PROGRA~1\CA\eTrust\INOCUL~1;C:\Program Files\Rational\common;C:\Program Files\Rational\Rose\TopLink\;C:\ANT\apache-ant-1.5.3-1\bin;C:\j2sdk1.4.2_01\bin, hibernate.jndi.url=iiop://localhost:2809, 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.0, user.home=C:\Documents and Settings\crvashi, user.timezone=America/New_York, java.awt.printerjob=sun.awt.windows.WPrinterJob, java.specification.version=1.4, file.encoding=Cp1252, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, user.name=crvashi, java.class.path=C:\BGMIT\apps\Contract_Service\build\classes;Z:\lib\activation.jar;Z:\lib\bootstrap.jar;Z:\lib\checkstyle.jar;Z:\lib\classes12.zip;Z:\lib\clover.jar;Z:\lib\commons-beanutils.jar;Z:\lib\commons-collections.jar;Z:\lib\commons-dbcp.jar;Z:\lib\commons-digester.jar;Z:\lib\commons-fileupload.jar;Z:\lib\commons-lang.jar;Z:\lib\commons-logging.jar;Z:\lib\commons-pool.jar;Z:\lib\commons-resources.jar;Z:\lib\commons-validator.jar;Z:\lib\crimson.jar;Z:\lib\dom4j.jar;Z:\lib\hibernate2.jar;Z:\lib\j2ee.jar;Z:\lib\jakarta-commons-logging-1.0.2.jar;Z:\lib\jakarta-oro.jar;Z:\lib\jaxp.jar;Z:\lib\jaxrpc-api.jar;Z:\lib\jbossall-client.jar;Z:\lib\jnp-client.jar;Z:\lib\junit.jar;Z:\lib\junit-3.8.1.jar;Z:\lib\junitperf.jar;Z:\lib\kilim.jar;Z:\lib\kilim-tools.jar;Z:\lib\log4j.jar;Z:\lib\log4j-1.2.6.jar;Z:\lib\mail.jar;Z:\lib\nanoxml-lite-2_2_1.jar;Z:\lib\rowset.jar;Z:\lib\saaj.jar;Z:\lib\servlet.jar;Z:\lib\struts.jar;Z:\lib\taglibs-datetime.jar;Z:\lib\taglibs-log.jar;Z:\lib\wsanttasks.jar;Z:\lib\xalan.jar;Z:\lib\xalan-0.19.1.jar;Z:\lib\xalan-2.5.1.jar;Z:\lib\xdb.jar;Z:\lib\xercesImpl.jar;Z:\lib\xercesImpl-2.4.0.jar;Z:\lib\xmlParserAPIs.jar;Z:\lib\xmlparserv2.jar;C:\BGMIT\apps\Contract_Service\lib\BGMFramework.jar;C:\BGMIT\apps\Contract_Service\lib\BGMDataHandlers.jar;C:\BGMIT\apps\Contract_Service\lib\BGM_EJB_ServiceFacade.jar;C:\temp\hibernate2.jar;C:\temp\cglib-2.0-beta1.jar;C:\temp\cglib-1.0.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\ant.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\c3p0.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\cglib-asm.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\commons-beanutils.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\commons-collections.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\commons-dbcp.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\commons-lang.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\commons-logging.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\commons-pool.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\connector.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\dom4j.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\jaas.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\jcs.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\jdbc2_0-stdext.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\jta.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\junit.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\odmg.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\optional.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\proxool.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\xalan.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\xerces.jar;G:\BgmIT\Software\Object Relational Mapping Tools\hibernate\hibernate-2.0.3\lib\xml-apis.jar, hibernate.show_sql=false, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', java.vm.specification.version=1.0, sun.arch.data.model=32, java.home=C:\j2sdk1.4.2_01\jre, hibernate.connection.url=jdbc:oracle:thin:@10.25.39.138:1521:BGMIT, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, java.specification.vendor=Sun Microsystems Inc., user.language=en, awt.toolkit=sun.awt.windows.WToolkit, java.vm.info=mixed mode, hibernate.cglib.use_reflection_optimizer=true, java.version=1.4.2_01, hibernate.jdbc.use_streams_for_binary=true, java.ext.dirs=C:\j2sdk1.4.2_01\jre\lib\ext, sun.boot.class.path=C:\j2sdk1.4.2_01\jre\lib\rt.jar;C:\j2sdk1.4.2_01\jre\lib\i18n.jar;C:\j2sdk1.4.2_01\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2_01\jre\lib\jsse.jar;C:\j2sdk1.4.2_01\jre\lib\jce.jar;C:\j2sdk1.4.2_01\jre\lib\charsets.jar;C:\j2sdk1.4.2_01\jre\classes, java.vendor=Sun Microsystems Inc., hibernate.jdbc.batch_size=0, file.separator=\, hibernate.query.imports=net.sf.hibernate.test, net.sf.hibernate.eg, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, hibernate.statement_cache.size=25, sun.cpu.endian=little, sun.io.unicode.encoding=UnicodeLittle, hibernate.jndi.class=com.ibm.websphere.naming.WsnInitialContextFactory, sun.cpu.isalist=pentium i486 i386}
15:40:06,039 INFO Dialect:83 - Using dialect: net.sf.hibernate.dialect.OracleDialect
15:40:06,054 INFO DriverManagerConnectionProvider:41 - Hibernate connection pool size: 1
15:40:06,132 INFO DriverManagerConnectionProvider:70 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@10.25.39.138:1521:BGMIT
15:40:06,132 INFO DriverManagerConnectionProvider:71 - connection properties: {user=BGM_CONTRACTS, password=BGM_CONTRACTS}
15:40:06,132 INFO PreparedStatementCache:60 - prepared statement cache size: 25
15:40:06,132 INFO SessionFactoryImpl:162 - Use outer join fetching: true
15:40:06,132 DEBUG DriverManagerConnectionProvider:77 - total checked-out connections: 0
15:40:06,132 DEBUG DriverManagerConnectionProvider:90 - opening new JDBC connection
15:40:07,070 DEBUG DriverManagerConnectionProvider:103 - created connection to: jdbc:oracle:thin:@10.25.39.138:1521:BGMIT, Isolation Level: 2
15:40:07,070 DEBUG DriverManagerConnectionProvider:117 - returning connection to pool, pool size: 1
15:40:07,070 INFO SessionFactoryImpl:185 - Use scrollable result sets: true
15:40:07,179 INFO ReflectHelper:328 - reflection optimizer disabled for: com.bunge.bgm.common.domain.user.Child, InvocationTargetException: null
15:40:07,210 INFO ReflectHelper:328 - reflection optimizer disabled for: com.bunge.bgm.common.domain.user.Parent, InvocationTargetException: null
15:40:07,413 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
15:40:07,413 DEBUG SessionFactoryObjectFactory:76 - registered: 8a990b1cf88eb96b00f88eb971f50000 (unnamed)
15:40:07,413 INFO SessionFactoryObjectFactory:82 - no JDNI name configured
15:40:07,413 INFO SessionFactoryImpl:269 - Query language substitutions: {no='N', true=1, yes='Y', false=0}
15:40:07,413 DEBUG SessionFactoryImpl:281 - instantiated session factory
15:40:07,492 DEBUG SessionImpl:413 - opened session
15:40:07,492 DEBUG JDBCTransaction:36 - begin
15:40:07,492 DEBUG DriverManagerConnectionProvider:77 - total checked-out connections: 0
15:40:07,507 DEBUG DriverManagerConnectionProvider:83 - using pooled JDBC connection, pool size: 0
15:40:07,507 DEBUG SessionImpl:656 - saving [com.bunge.bgm.common.domain.user.Parent#1]
15:40:07,507 DEBUG Cascades:336 - processing cascades for: com.bunge.bgm.common.domain.user.Parent
15:40:07,507 DEBUG Cascades:344 - done processing cascades for: com.bunge.bgm.common.domain.user.Parent
15:40:07,523 DEBUG SessionImpl:2520 - Wrapped collection in role: com.bunge.bgm.common.domain.user.Parent._child
15:40:07,523 DEBUG Cascades:336 - processing cascades for: com.bunge.bgm.common.domain.user.Parent
15:40:07,538 DEBUG Cascades:275 - cascading to collection: com.bunge.bgm.common.domain.user.Parent._child
15:40:07,538 DEBUG Cascades:87 - cascading to saveOrUpdate()
15:40:07,538 DEBUG Cascades:237 - unsaved-value strategy NULL
15:40:07,538 DEBUG SessionImpl:1205 - saveOrUpdate() previously saved instance with id: 1
15:40:07,538 DEBUG SessionImpl:1270 - updating [com.bunge.bgm.common.domain.user.Child#1]
15:40:07,538 DEBUG Cascades:344 - done processing cascades for: com.bunge.bgm.common.domain.user.Parent
15:40:07,538 DEBUG JDBCTransaction:54 - commit
15:40:07,538 DEBUG SessionImpl:2011 - flushing session
15:40:07,554 DEBUG Cascades:336 - processing cascades for: com.bunge.bgm.common.domain.user.Parent
15:40:07,554 DEBUG Cascades:275 - cascading to collection: com.bunge.bgm.common.domain.user.Parent._child
15:40:07,554 DEBUG Cascades:87 - cascading to saveOrUpdate()
15:40:07,554 DEBUG SessionImpl:1183 - saveOrUpdate() persistent instance
15:40:07,554 DEBUG Cascades:344 - done processing cascades for: com.bunge.bgm.common.domain.user.Parent
15:40:07,554 DEBUG SessionImpl:2113 - Flushing entities and processing referenced collections
15:40:07,570 DEBUG SessionImpl:2550 - Collection found: [com.bunge.bgm.common.domain.user.Parent._child#1], was: [<unreferenced>]
15:40:07,570 DEBUG SessionImpl:2209 - Updating entity: [com.bunge.bgm.common.domain.user.Child#1]
15:40:07,570 DEBUG SessionImpl:2397 - Processing unreferenced collections
15:40:07,570 DEBUG SessionImpl:2408 - Scheduling collection removes/(re)creates/updates
15:40:07,570 DEBUG SessionImpl:2023 - Flushed: 1 insertions, 1 updates, 0 deletions to 2 objects
15:40:07,585 DEBUG SessionImpl:2028 - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
15:40:07,585 DEBUG SessionImpl:2058 - executing flush
15:40:07,585 DEBUG EntityPersister:464 - Inserting entity: com.bunge.bgm.common.domain.user.Parent#1
15:40:07,585 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
15:40:07,585 DEBUG SessionFactoryImpl:526 - prepared statement get: insert into BGM_COMPONENTS.T_PARENT (NAME, ID) values (?, ?)
15:40:07,632 DEBUG EntityPersister:366 - Dehydrating entity: com.bunge.bgm.common.domain.user.Parent#1
15:40:08,835 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
15:40:08,835 DEBUG EntityPersister:617 - Updating entity: com.bunge.bgm.common.domain.user.Child#1
15:40:08,851 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
15:40:08,851 DEBUG SessionFactoryImpl:526 - prepared statement get: update BGM_COMPONENTS.T_CHILD set CHILD_NAME=?, PARENT_ID=? where CHILD_ID=?
15:40:08,851 DEBUG EntityPersister:366 - Dehydrating entity: com.bunge.bgm.common.domain.user.Child#1
15:40:08,991 DEBUG SessionImpl:447 - transaction completion
15:40:08,991 DEBUG JDBCTransaction:77 - rollback
15:40:09,054 DEBUG SessionImpl:447 - transaction completion
15:40:09,054 DEBUG SessionImpl:435 - closing session
15:40:09,054 DEBUG SessionImpl:2930 - disconnecting session
15:40:09,054 DEBUG DriverManagerConnectionProvider:117 - returning connection to pool, pool size: 1
15:40:09,054 DEBUG SessionImpl:447 - transaction completion
15:40:09,070 DEBUG SessionImpl:2981 - running Session.finalize()
net.sf.hibernate.HibernateException: SQL update or deletion failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:611)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:31)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2100)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2062)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:57)
at com.bunge.bgm.contract.business.domain.user.UserMain.createParent(UserMain.java:81)
at com.bunge.bgm.contract.business.domain.user.UserMain.main(UserMain.java:520)
Is it possible that i can create both parent and child in session.save(parent). My mapping file for parent is :
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping schema="BGM_COMPONENTS">
<class name="com.bunge.bgm.common.domain.user.Parent" table="T_PARENT">
<id name="_id" column="ID" type="integer">
<generator class="assigned"/>
</id>
<property name="_name" column="NAME"/>
<bag name="_child" cascade="all" inverse="true">
<key column="CHILD_ID"/>
<one-to-many class="com.bunge.bgm.common.domain.user.Child"/>
</bag>
</class>
</hibernate-mapping>
<!-- parsed in 0ms -->
I am not able to find out how does hibernate handles such scenario. I am using Hibernate2.0.3. Any help is greatly appreciated.