Hibernate version:
2.1.6
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.gfs.corp.component.uoc.dto.Parent" table="GFS.PARENT">
<id name="name" type="string" column="name">
<generator class="assigned">
</generator>
</id>
<set name="children" inverse="true" cascade="all-delete-orphan">
<key column="parent_name"/>
<one-to-many class="com.gfs.corp.component.uoc.dto.Child"/>
</set>
</class>
<class name="com.gfs.corp.component.uoc.dto.Child" table="GFS.CHILD">
<id name="name" type="string" column="name">
<generator class="assigned">
</generator>
</id>
<many-to-one name="parent" column="parent_name" class="com.gfs.corp.component.uoc.dto.Parent"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Transaction trx = session.beginTransaction();
Parent stephen = new Parent();
stephen.setName("Stephen Earl");
Child simon = new Child();
simon.setName("Simon Earl");
stephen.addChild(simon);
simon.setParent(stephen);
session.save(stephen);
trx.commit();
Full stack trace of any exception that occurs:
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
Hibernate: insert into GFS.PARENT (name) values (?)
Hibernate: update GFS.CHILD set parent_name=? where name=?
Debug level Hibernate log excerpt:
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.6
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: uoc.hbm.xml
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: com.gfs.corp.component.uoc.dto.Parent -> GFS.PARENT
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: com.gfs.corp.component.uoc.dto.Child -> GFS.CHILD
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: HibernateSessionFactory
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: com.gfs.corp.component.uoc.dto.Parent.children -> GFS.CHILD
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Nov 1, 2004 9:59:38 AM net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.Oracle9Dialect
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
Nov 1, 2004 9:59:38 AM net.sf.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Nov 1, 2004 9:59:38 AM net.sf.hibernate.connection.DatasourceConnectionProvider configure
INFO: Using datasource: DefaultDS
Nov 1, 2004 9:59:38 AM net.sf.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: net.sf.hibernate.transaction.JTATransactionFactory
Nov 1, 2004 9:59:38 AM net.sf.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Nov 1, 2004 9:59:38 AM net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: instantiating TransactionManagerLookup: net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
Nov 1, 2004 9:59:38 AM net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: instantiated TransactionManagerLookup
Nov 1, 2004 9:59:38 AM net.sf.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Nov 1, 2004 9:59:38 AM net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: instantiating TransactionManagerLookup: net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
Nov 1, 2004 9:59:38 AM net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: instantiated TransactionManagerLookup
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): false
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: echoing all SQL to stdout
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.hibernate.cache.EhCacheProvider
Nov 1, 2004 9:59:38 AM net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
Nov 1, 2004 9:59:38 AM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Nov 1, 2004 9:59:39 AM net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Factory name: HibernateSessionFactory
Nov 1, 2004 9:59:39 AM net.sf.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
Nov 1, 2004 9:59:39 AM net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Bound factory to JNDI name: HibernateSessionFactory
Nov 1, 2004 9:59:39 AM net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
WARNING: InitialContext did not implement EventContext
Nov 1, 2004 9:59:39 AM net.sf.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
I must be doing something fundamentally wrong here. When I attempt to save / persist a Parent object with one Child object in it children collection I only get the Parent object saved / persisted. This example is right out of the Hibernate in Action book. Can someone comment on what I might be doing wrong which would prevent the Child object(s) from being persisted?
Thanks in advance,
Steve...
|