-->
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.  [ 5 posts ] 
Author Message
 Post subject: Lazy loading and parent/child relationships
PostPosted: Wed Feb 11, 2004 10:12 am 
Newbie

Joined: Tue Feb 10, 2004 4:31 pm
Posts: 3
I am having a difficult time successfully implementing a parent/child relationship in Hiberbate and I know I am missing something but I need a second pair of eyes. I have read the docs and have set the appropriate tags in my parent; inverse="true", cascade="all-delete-orphan", etc. and my child one-to-many tag. I am running Hibernate 2.1, MySql 4.0.17, and xDoclet 1.2 to generate the Hiberbate mapping xml files.

The junit code for inserting a new record is :

FamilyMember member1 = new FamilyMember();
member1.setBirthDate(new Date(7, 14, 2001));
member1.setGender("Female");
member1.setName("Sally");
member1.setId(2);

family.add(member1);

Resident resident = new Resident();
resident.setAddress(address);
resident.setEmailAddress("myName@yahoo.com");
resident.setFirstName("My");
resident.setLastName("Name");
resident.setId(1);

Transaction tx = null;
Session session = HibernateUtil.currentSession();
try {


tx = session.beginTransaction();
session.save(resident);
session.flush();
tx.commit();
} catch (HibernateException e) {
tx.rollback();
throw e;
} finally {
session.disconnect();
session.close();

It looks like Hibernate is attempting to update the child record instead of performing an insert. I was thinking by setting the inverse tag to true the sequence would be insert parent (Resident) then insert child (FamilyMembers). What am I missing here?

Here is the debug info and stack trace as a result of the error.

.0 [main] INFO cfg.Environment - Hibernate 2.1.1
30 [main] INFO cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.connection.isolation=4, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.query.imports=cirrus.hibernate.test, hibernate.connection.username=root, hibernate.connection.url=jdbc:mysql://localhost:3306/brookside, hibernate.show_sql=true, hibernate.connection.password=, hibernate.connection.pool_size=2}
30 [main] INFO cfg.Environment - using java.io streams to persist binary types
40 [main] INFO cfg.Environment - using CGLIB reflection optimizer
60 [main] INFO cfg.Configuration - configuring from resource: /hibernate.cfg.xml
60 [main] INFO cfg.Configuration - Configuration resource: /hibernate.cfg.xml
250 [main] DEBUG util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath under net/sf/hibernate/
260 [main] DEBUG util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... on-2.0.dtd in classpath
350 [main] DEBUG cfg.Configuration - connection.driver_class=com.mysql.jdbc.Driver
350 [main] DEBUG cfg.Configuration - connection.url=jdbc:mysql://localhost:3306/brookside
360 [main] DEBUG cfg.Configuration - show_sql=false
360 [main] DEBUG cfg.Configuration - use_outer_join=false
360 [main] DEBUG cfg.Configuration - dialect=net.sf.hibernate.dialect.MySQLDialect
360 [main] DEBUG cfg.Configuration - null<-org.dom4j.tree.DefaultAttribute@1125127 [Attribute: name resource value "Resident.hbm.xml"]
360 [main] INFO cfg.Configuration - Mapping resource: Resident.hbm.xml
370 [main] DEBUG util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
370 [main] DEBUG util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
661 [main] INFO cfg.Binder - Mapping class: org.brookside.resident.Resident -> RESIDENT
811 [main] DEBUG cfg.Binder - Mapped property: id -> RESIDENT_ID, type: integer
841 [main] DEBUG cfg.Binder - Mapped property: firstName -> FIRST_NAME, type: string
851 [main] DEBUG cfg.Binder - Mapped property: lastName -> LAST_NAME, type: string
851 [main] DEBUG cfg.Binder - Mapped property: emailAddress -> EMAIL_ADDRESS, type: string
891 [main] DEBUG cfg.Binder - Mapped property: address, type: org.brookside.lib.PostalAddress
921 [main] DEBUG cfg.Binder - Mapped property: familyMembers, type: java.util.Set
921 [main] DEBUG cfg.Binder - Mapped property: phoneNumbers, type: java.util.Set
921 [main] DEBUG cfg.Configuration - null<-org.dom4j.tree.DefaultAttribute@641e9a [Attribute: name resource value "State.hbm.xml"]
921 [main] INFO cfg.Configuration - Mapping resource: State.hbm.xml
931 [main] DEBUG util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
931 [main] DEBUG util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
981 [main] INFO cfg.Binder - Mapping class: org.brookside.lib.State -> STATE
981 [main] DEBUG cfg.Binder - Mapped property: id -> STATE_ID, type: integer
981 [main] DEBUG cfg.Binder - Mapped property: shortName -> ABBREVIATION, type: string
981 [main] DEBUG cfg.Binder - Mapped property: longName -> NAME, type: string
981 [main] DEBUG cfg.Configuration - null<-org.dom4j.tree.DefaultAttribute@19b5393 [Attribute: name resource value "Phone.hbm.xml"]
981 [main] INFO cfg.Configuration - Mapping resource: Phone.hbm.xml
1001 [main] DEBUG util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
1001 [main] DEBUG util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
1021 [main] INFO cfg.Binder - Mapping class: org.brookside.lib.Phone -> PHONE_NUMBER
1031 [main] DEBUG cfg.Binder - Mapped property: phone_id -> PHONE_ID, type: integer
1031 [main] DEBUG cfg.Binder - Mapped property: number -> NUMBER, type: string
1031 [main] DEBUG cfg.Binder - Mapped property: type, type: org.brookside.lib.PhoneType
1031 [main] DEBUG cfg.Configuration - null<-org.dom4j.tree.DefaultAttribute@4e79f1 [Attribute: name resource value "PostalAddress.hbm.xml"]
1031 [main] INFO cfg.Configuration - Mapping resource: PostalAddress.hbm.xml
1041 [main] DEBUG util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
1041 [main] DEBUG util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
1081 [main] INFO cfg.Binder - Mapping class: org.brookside.lib.PostalAddress -> POSTAL_ADDRESS
1081 [main] DEBUG cfg.Binder - Mapped property: id -> POSTAL_ADDRESS_ID, type: integer
1081 [main] DEBUG cfg.Binder - Mapped property: addressLine1 -> ADDRESS_ONE, type: string
1091 [main] DEBUG cfg.Binder - Mapped property: addressLine2 -> ADDRESS_TWO, type: string
1122 [main] DEBUG cfg.Binder - Mapped property: addressLine3 -> ADDRESS_THREE, type: string
1122 [main] DEBUG cfg.Binder - Mapped property: state, type: org.brookside.lib.State
1122 [main] DEBUG cfg.Binder - Mapped property: city -> CITY, type: string
1142 [main] DEBUG cfg.Binder - Mapped property: zipCode -> ZIP_CODE, type: string
1542 [main] DEBUG cfg.Binder - Mapped property: zipCode -> ZIP_CODE, type: org.brookside.lib.ZipCode
1542 [main] DEBUG cfg.Configuration - null<-org.dom4j.tree.DefaultAttribute@157aa53 [Attribute: name resource value "FamilyMember.hbm.xml"]
1542 [main] INFO cfg.Configuration - Mapping resource: FamilyMember.hbm.xml
1552 [main] DEBUG util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
1552 [main] DEBUG util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
1572 [main] INFO cfg.Binder - Mapping class: org.brookside.resident.FamilyMember -> FAMILY_MEMBER
1572 [main] DEBUG cfg.Binder - Mapped property: id -> FAMILY_MEMBER_ID, type: integer
1572 [main] DEBUG cfg.Binder - Mapped property: resident -> RESIDENT_ID, type: org.brookside.resident.Resident
1572 [main] DEBUG cfg.Binder - Mapped property: name -> NAME, type: string
1602 [main] WARN type.CustomType - custom type does not implement Serializable: class org.hibernate.type.CustomDateType
1602 [main] DEBUG cfg.Binder - Mapped property: birthDate -> BIRTH_DATE, type: org.hibernate.type.CustomDateType
1602 [main] DEBUG cfg.Binder - Mapped property: gender -> GENDER, type: string
1602 [main] DEBUG cfg.Configuration - null<-org.dom4j.tree.DefaultAttribute@1c56c60 [Attribute: name resource value "PhoneType.hbm.xml"]
1602 [main] INFO cfg.Configuration - Mapping resource: PhoneType.hbm.xml
1612 [main] DEBUG util.DTDEntityResolver - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
1612 [main] DEBUG util.DTDEntityResolver - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
1632 [main] INFO cfg.Binder - Mapping class: org.brookside.lib.PhoneType -> PHONE_NUMBER_TYPE
1642 [main] DEBUG cfg.Binder - Mapped property: id -> ID, type: integer
1642 [main] DEBUG cfg.Binder - Mapped property: description -> DESCRIPTION, type: string
1642 [main] INFO cfg.Configuration - Configured SessionFactory: null
1642 [main] DEBUG cfg.Configuration - properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=, sun.boot.library.path=C:\j2sdk1.4.2\jre\bin, java.vm.version=1.4.2-b28, 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, use_outer_join=false, user.country=US, sun.os.patch.level=Service Pack 2, hibernate.connection.isolation=4, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\Personal\BB, 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, java.io.tmpdir=C:\DOCUME~1\kdenson\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\bin;.;C:\WINNT\System32;C:\WINNT;C:\oracle\ora81\bin;C:\Program Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\ODI\PSEPROJ\bin;C:\openSource\apache-ant-1.5.4\bin;C:\UnixUtils;C:\UnixUtils\bin;C:\UnixUtils\usr\local\wbin;c:\jad;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\cvsnt;C:\Program Files\NUnit V2.1\bin;C:\WINNT\Microsoft.NET\Framework\v1.0.3705, java.specification.name=Java Platform API Specification, java.class.version=48.0, hibernate.connection.pool_size=2, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.0, user.home=C:\Documents and Settings\kdenson, user.timezone=America/New_York, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.4, hibernate.connection.driver_class=com.mysql.jdbc.Driver, show_sql=false, java.class.path=C:\IntelliJ-IDEA-3.0.5\lib\junit.jar;C:\Personal\BB\build\classes\test;C:\Personal\BB\build\classes;C:\Personal\BB\build\classes\main;C:\Personal\BB\build\hibernate;C:\Personal\brookside web\lib\hibernate2.jar;C:\openSource\hibernate-2.1\lib\ehcache.jar;C:\Personal\brookside web\lib\cglib2.jar;C:\j2sdkee1.3.1\lib\j2ee.jar;C:\openSource\jakarta-log4j-1.2.8\dist\lib\log4j-1.2.8.jar;C:\Personal\BB\lib\commons-beanutils.jar;C:\Personal\BB\lib\commons-collections.jar;C:\Personal\BB\lib\commons-digester.jar;C:\Personal\BB\lib\commons-lang.jar;C:\Personal\BB\lib\commons-logging.jar;C:\Personal\BB\lib\jakarta-oro-2.0.7.jar;C:\openSource\junit3.8.1\junit.jar;C:\openSource\dbunit-1.5.1\lib\dbunit.jar;C:\Personal\BB\lib\javax.servlet.jar;C:\Personal\BB\lib\log4j.jar;C:\Personal\BB\lib\mm.mysql-2.0.9-bin.jar;C:\Personal\BB\lib\odmg.jar;C:\Personal\BB\lib\struts.jar;C:\Personal\BB\lib\xalan.jar;C:\Personal\BB\lib\dom4j.jar;C:\Personal\BB\lib\cglib-asm.jar;C:\j2sdk1.4.2\jre\lib\charsets.jar;C:\j2sdk1.4.2\jre\lib\jce.jar;C:\j2sdk1.4.2\jre\lib\jsse.jar;C:\j2sdk1.4.2\jre\lib\plugin.jar;C:\j2sdk1.4.2\jre\lib\rt.jar;C:\j2sdk1.4.2\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2\jre\lib\ext\dnsns.jar;C:\j2sdk1.4.2\jre\lib\ext\ldapsec.jar;C:\j2sdk1.4.2\jre\lib\ext\localedata.jar;C:\j2sdk1.4.2\jre\lib\ext\sunjce_provider.jar;C:\Personal\brookside web\build\deployments\Brookside.jar;C:\Personal\BB\build\classes\test;C:\Personal\brookside web\lib\mysql-connector-java-3.0.10-stable-bin.jar;C:\IntelliJ-IDEA-3.0.5\lib\idea_rt.jar, user.name=kdenson, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.show_sql=false, java.vm.specification.version=1.0, java.home=C:\j2sdk1.4.2\jre, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost:3306/brookside, 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:\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, connection.driver_class=com.mysql.jdbc.Driver, file.separator=\, hibernate.query.imports=cirrus.hibernate.test, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, hibernate.use_outer_join=false, connection.url=jdbc:mysql://localhost:3306/brookside, dialect=net.sf.hibernate.dialect.MySQLDialect, sun.cpu.isalist=pentium i486 i386}
1662 [main] INFO cfg.Configuration - processing one-to-many association mappings
1662 [main] DEBUG cfg.Binder - Second pass for collection: org.brookside.resident.Resident.familyMembers
1672 [main] INFO cfg.Binder - Mapping collection: org.brookside.resident.Resident.familyMembers -> FAMILY_MEMBER
1672 [main] DEBUG cfg.Binder - Mapped collection key: RESIDENT_ID, one-to-many: org.brookside.resident.FamilyMember
1672 [main] DEBUG cfg.Binder - Second pass for collection: org.brookside.resident.Resident.phoneNumbers
1672 [main] INFO cfg.Binder - Mapping collection: org.brookside.resident.Resident.phoneNumbers -> PHONE_NUMBER
1672 [main] DEBUG cfg.Binder - Mapped collection key: RESIDENT_ID, one-to-many: org.brookside.lib.Phone
1672 [main] INFO cfg.Configuration - processing one-to-one association property references
1672 [main] INFO cfg.Configuration - processing foreign key constraints
1672 [main] DEBUG cfg.Configuration - resolving reference to class: org.brookside.resident.Resident
1672 [main] DEBUG cfg.Configuration - resolving reference to class: org.brookside.resident.Resident
1802 [main] INFO dialect.Dialect - Using dialect: net.sf.hibernate.dialect.MySQLDialect
1813 [main] INFO cfg.SettingsFactory - Use outer join fetching: false
1823 [main] INFO connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
1823 [main] INFO connection.DriverManagerConnectionProvider - Hibernate connection pool size: 2
1823 [main] INFO connection.DriverManagerConnectionProvider - JDBC isolation level: REPEATABLE_READ
1843 [main] INFO connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/brookside
1843 [main] INFO connection.DriverManagerConnectionProvider - connection properties: {user=root, password=}
1863 [main] INFO transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
1863 [main] DEBUG connection.DriverManagerConnectionProvider - total checked-out connections: 0
1863 [main] DEBUG connection.DriverManagerConnectionProvider - opening new JDBC connection
2674 [main] DEBUG connection.DriverManagerConnectionProvider - created connection to: jdbc:mysql://localhost:3306/brookside, Isolation Level: 4
2674 [main] DEBUG connection.DriverManagerConnectionProvider - returning connection to pool, pool size: 1
2674 [main] INFO cfg.SettingsFactory - Use scrollable result sets: true
2674 [main] INFO cfg.SettingsFactory - Query language substitutions: {no='N', true=1, yes='Y', false=0}
2684 [main] INFO cfg.SettingsFactory - cache provider: net.sf.ehcache.hibernate.Provider
2724 [main] INFO cfg.Configuration - instantiating and configuring caches
2784 [main] INFO impl.SessionFactoryImpl - building session factory
2784 [main] DEBUG impl.SessionFactoryImpl - instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=, sun.boot.library.path=C:\j2sdk1.4.2\jre\bin, java.vm.version=1.4.2-b28, 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, use_outer_join=false, user.country=US, sun.os.patch.level=Service Pack 2, hibernate.connection.isolation=4, java.vm.specification.name=Java Virtual Machine Specification, user.dir=C:\Personal\BB, 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, java.io.tmpdir=C:\DOCUME~1\kdenson\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\bin;.;C:\WINNT\System32;C:\WINNT;C:\oracle\ora81\bin;C:\Program Files\Oracle\jre\1.1.7\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\ODI\PSEPROJ\bin;C:\openSource\apache-ant-1.5.4\bin;C:\UnixUtils;C:\UnixUtils\bin;C:\UnixUtils\usr\local\wbin;c:\jad;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\cvsnt;C:\Program Files\NUnit V2.1\bin;C:\WINNT\Microsoft.NET\Framework\v1.0.3705, java.specification.name=Java Platform API Specification, java.class.version=48.0, hibernate.connection.pool_size=2, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.0, user.home=C:\Documents and Settings\kdenson, user.timezone=America/New_York, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.4, hibernate.connection.driver_class=com.mysql.jdbc.Driver, show_sql=false, java.class.path=C:\IntelliJ-IDEA-3.0.5\lib\junit.jar;C:\Personal\BB\build\classes\test;C:\Personal\BB\build\classes;C:\Personal\BB\build\classes\main;C:\Personal\BB\build\hibernate;C:\Personal\brookside web\lib\hibernate2.jar;C:\openSource\hibernate-2.1\lib\ehcache.jar;C:\Personal\brookside web\lib\cglib2.jar;C:\j2sdkee1.3.1\lib\j2ee.jar;C:\openSource\jakarta-log4j-1.2.8\dist\lib\log4j-1.2.8.jar;C:\Personal\BB\lib\commons-beanutils.jar;C:\Personal\BB\lib\commons-collections.jar;C:\Personal\BB\lib\commons-digester.jar;C:\Personal\BB\lib\commons-lang.jar;C:\Personal\BB\lib\commons-logging.jar;C:\Personal\BB\lib\jakarta-oro-2.0.7.jar;C:\openSource\junit3.8.1\junit.jar;C:\openSource\dbunit-1.5.1\lib\dbunit.jar;C:\Personal\BB\lib\javax.servlet.jar;C:\Personal\BB\lib\log4j.jar;C:\Personal\BB\lib\mm.mysql-2.0.9-bin.jar;C:\Personal\BB\lib\odmg.jar;C:\Personal\BB\lib\struts.jar;C:\Personal\BB\lib\xalan.jar;C:\Personal\BB\lib\dom4j.jar;C:\Personal\BB\lib\cglib-asm.jar;C:\j2sdk1.4.2\jre\lib\charsets.jar;C:\j2sdk1.4.2\jre\lib\jce.jar;C:\j2sdk1.4.2\jre\lib\jsse.jar;C:\j2sdk1.4.2\jre\lib\plugin.jar;C:\j2sdk1.4.2\jre\lib\rt.jar;C:\j2sdk1.4.2\jre\lib\sunrsasign.jar;C:\j2sdk1.4.2\jre\lib\ext\dnsns.jar;C:\j2sdk1.4.2\jre\lib\ext\ldapsec.jar;C:\j2sdk1.4.2\jre\lib\ext\localedata.jar;C:\j2sdk1.4.2\jre\lib\ext\sunjce_provider.jar;C:\Personal\brookside web\build\deployments\Brookside.jar;C:\Personal\BB\build\classes\test;C:\Personal\brookside web\lib\mysql-connector-java-3.0.10-stable-bin.jar;C:\IntelliJ-IDEA-3.0.5\lib\idea_rt.jar, user.name=kdenson, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.show_sql=false, java.vm.specification.version=1.0, java.home=C:\j2sdk1.4.2\jre, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.url=jdbc:mysql://localhost:3306/brookside, 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:\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, connection.driver_class=com.mysql.jdbc.Driver, file.separator=\, hibernate.query.imports=cirrus.hibernate.test, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, hibernate.use_outer_join=false, connection.url=jdbc:mysql://localhost:3306/brookside, dialect=net.sf.hibernate.dialect.MySQLDialect, sun.cpu.isalist=pentium i486 i386}
3525 [main] DEBUG impl.SessionFactoryObjectFactory - initializing class SessionFactoryObjectFactory
3535 [main] DEBUG impl.SessionFactoryObjectFactory - registered: ff808081faa2b76100faa2b764460000 (unnamed)
3535 [main] INFO impl.SessionFactoryObjectFactory - no JNDI name configured
3535 [main] DEBUG impl.SessionFactoryImpl - instantiated session factory
3665 [main] DEBUG impl.SessionImpl - opened session
3675 [main] DEBUG transaction.JDBCTransaction - begin
3675 [main] DEBUG connection.DriverManagerConnectionProvider - total checked-out connections: 0
3675 [main] DEBUG connection.DriverManagerConnectionProvider - using pooled JDBC connection, pool size: 0
3675 [main] DEBUG transaction.JDBCTransaction - current autocommit status:false
3695 [main] DEBUG impl.SessionImpl - saving [org.brookside.resident.Resident#1]
3695 [main] DEBUG engine.Cascades - processing cascades for: org.brookside.resident.Resident
3695 [main] DEBUG engine.Cascades - done processing cascades for: org.brookside.resident.Resident
3695 [main] DEBUG engine.Cascades - id unsaved-value strategy NULL
3705 [main] DEBUG engine.Cascades - processing cascades for: org.brookside.resident.Resident
3705 [main] DEBUG engine.Cascades - cascading to collection: org.brookside.resident.Resident.familyMembers
3705 [main] DEBUG engine.Cascades - cascading to saveOrUpdate()
3715 [main] DEBUG engine.Cascades - id unsaved-value strategy NULL
3715 [main] DEBUG impl.SessionImpl - saveOrUpdate() previously saved instance with id: 2
3715 [main] DEBUG impl.SessionImpl - updating [org.brookside.resident.FamilyMember#2]
3715 [main] DEBUG engine.Cascades - processing cascades for: org.brookside.resident.FamilyMember
3725 [main] DEBUG engine.Cascades - cascading to saveOrUpdate()
3725 [main] DEBUG impl.SessionImpl - saveOrUpdate() persistent instance
3725 [main] DEBUG engine.Cascades - done processing cascades for: org.brookside.resident.FamilyMember
3725 [main] DEBUG engine.Cascades - done processing cascades for: org.brookside.resident.Resident
3725 [main] DEBUG impl.SessionImpl - object already associated with session
3725 [main] DEBUG impl.SessionImpl - saving [org.brookside.resident.FamilyMember#1]
3725 [main] DEBUG engine.Cascades - processing cascades for: org.brookside.resident.FamilyMember
3725 [main] DEBUG engine.Cascades - cascading to saveOrUpdate()
3725 [main] DEBUG impl.SessionImpl - saveOrUpdate() persistent instance
3725 [main] DEBUG engine.Cascades - done processing cascades for: org.brookside.resident.FamilyMember
3755 [main] DEBUG engine.Cascades - processing cascades for: org.brookside.resident.FamilyMember
3755 [main] DEBUG engine.Cascades - done processing cascades for: org.brookside.resident.FamilyMember
3755 [main] DEBUG impl.SessionImpl - flushing session
3765 [main] DEBUG engine.Cascades - processing cascades for: org.brookside.resident.Resident
3765 [main] DEBUG engine.Cascades - cascading to collection: org.brookside.resident.Resident.familyMembers
3765 [main] DEBUG engine.Cascades - cascading to saveOrUpdate()
3765 [main] DEBUG impl.SessionImpl - saveOrUpdate() persistent instance
3765 [main] DEBUG engine.Cascades - done processing cascades for: org.brookside.resident.Resident
3765 [main] DEBUG engine.Cascades - processing cascades for: org.brookside.resident.FamilyMember
3775 [main] DEBUG engine.Cascades - cascading to saveOrUpdate()
3775 [main] DEBUG impl.SessionImpl - saveOrUpdate() persistent instance
3775 [main] DEBUG engine.Cascades - done processing cascades for: org.brookside.resident.FamilyMember
3775 [main] DEBUG engine.Cascades - processing cascades for: org.brookside.resident.FamilyMember
3775 [main] DEBUG engine.Cascades - cascading to saveOrUpdate()
3775 [main] DEBUG impl.SessionImpl - saveOrUpdate() persistent instance
3775 [main] DEBUG engine.Cascades - done processing cascades for: org.brookside.resident.FamilyMember
3775 [main] DEBUG impl.SessionImpl - Flushing entities and processing referenced collections
3795 [main] DEBUG impl.WrapVisitor - Wrapped collection in role: org.brookside.resident.Resident.familyMembers
3795 [main] DEBUG impl.SessionImpl - Collection found: [org.brookside.resident.Resident.familyMembers#1], was: [<unreferenced>]
3795 [main] DEBUG impl.SessionImpl - Updating entity: [org.brookside.resident.FamilyMember#2]
3805 [main] DEBUG impl.SessionImpl - Processing unreferenced collections
3805 [main] DEBUG impl.SessionImpl - Scheduling collection removes/(re)creates/updates
3805 [main] DEBUG impl.SessionImpl - Flushed: 2 insertions, 1 updates, 0 deletions to 3 objects
3805 [main] DEBUG impl.SessionImpl - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
3815 [main] DEBUG impl.Printer - listing entities:
3815 [main] DEBUG impl.Printer - org.brookside.resident.FamilyMember{gender=Male, resident=Resident#1, name=Jim, birthDate=4/27/2003, id=1}
3825 [main] DEBUG impl.Printer - org.brookside.resident.Resident{familyMembers=[FamilyMember#2], phoneNumbers=null, emailAddress=myName@yahoo.com, address=PostalAddress#1, firstName=My, id=1, lastName=Name}
3825 [main] DEBUG impl.Printer - org.brookside.resident.FamilyMember{gender=Female, resident=Resident#1, name=Sally, birthDate=7/14/2001, id=2}
3825 [main] DEBUG impl.SessionImpl - executing flush
3825 [main] DEBUG persister.EntityPersister - Inserting entity: [org.brookside.resident.Resident#1]
3825 [main] DEBUG impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
3825 [main] DEBUG hibernate.SQL - insert into RESIDENT (FIRST_NAME, LAST_NAME, EMAIL_ADDRESS, RESIDENT_ID) values (?, ?, ?, ?)
3825 [main] DEBUG impl.BatcherImpl - preparing statement
3855 [main] DEBUG persister.EntityPersister - Dehydrating entity: [org.brookside.resident.Resident#1]
3875 [main] DEBUG persister.EntityPersister - Inserting entity: [org.brookside.resident.FamilyMember#1]
3875 [main] DEBUG impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
3875 [main] DEBUG impl.BatcherImpl - closing statement
3875 [main] DEBUG impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
3875 [main] DEBUG hibernate.SQL - insert into FAMILY_MEMBER (NAME, BIRTH_DATE, GENDER, FAMILY_MEMBER_ID) values (?, ?, ?, ?)
3875 [main] DEBUG impl.BatcherImpl - preparing statement
3875 [main] DEBUG persister.EntityPersister - Dehydrating entity: [org.brookside.resident.FamilyMember#1]
3885 [main] DEBUG impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
3885 [main] DEBUG impl.BatcherImpl - closing statement
3885 [main] DEBUG persister.EntityPersister - Updating entity: [org.brookside.resident.FamilyMember#2]
3896 [main] DEBUG impl.BatcherImpl - about to open: 0 open PreparedStatements, 0 open ResultSets
3896 [main] DEBUG hibernate.SQL - update FAMILY_MEMBER set NAME=?, BIRTH_DATE=?, GENDER=? where FAMILY_MEMBER_ID=?
3896 [main] DEBUG impl.BatcherImpl - preparing statement
3896 [main] DEBUG persister.EntityPersister - Dehydrating entity: [org.brookside.resident.FamilyMember#2]
3926 [main] ERROR impl.SessionImpl - Could not synchronize database state with session
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:672)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:625)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2308)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2262)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2187)
at org.brookside.resident.ResidentTestCase.testInsert(ResidentTestCase.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at junit.textui.TestRunner.start(TestRunner.java:172)
at com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12)
3946 [main] DEBUG transaction.JDBCTransaction - rollback
4016 [main] DEBUG impl.SessionImpl - transaction completion


Here is the mapping for the parent:
<?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="org.brookside.resident.Resident"
table="RESIDENT"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="RESIDENT_ID"
type="int"
>
<generator class="assigned">
</generator>
</id>

<property
name="firstName"
type="string"
update="true"
insert="true"
column="FIRST_NAME"
not-null="false"
/>

<property
name="lastName"
type="string"
update="true"
insert="true"
column="LAST_NAME"
not-null="false"
/>

<property
name="emailAddress"
type="string"
update="true"
insert="true"
column="EMAIL_ADDRESS"
not-null="true"
/>

<one-to-one
name="address"
class="org.brookside.lib.PostalAddress"
cascade="none"
outer-join="auto"
constrained="false"
/>

<set
name="familyMembers"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
order-by="name"
>

<key
column="RESIDENT_ID"
/>

<one-to-many
class="org.brookside.resident.FamilyMember"
/>
</set>

<set
name="phoneNumbers"
table="phone_number"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="RESIDENT_ID"
/>

<one-to-many
class="org.brookside.lib.Phone"
/>
</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Resident.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


and the mapping for the child:
<?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="org.brookside.resident.FamilyMember"
table="FAMILY_MEMBER"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="FAMILY_MEMBER_ID"
type="int"
>
<generator class="assigned">
</generator>
</id>

<many-to-one
name="resident"
class="org.brookside.resident.Resident"
cascade="none"
outer-join="auto"
update="false"
insert="false"
column="RESIDENT_ID"
/>

<property
name="name"
type="string"
update="true"
insert="true"
column="NAME"
not-null="false"
/>

<property
name="birthDate"
type="org.hibernate.type.CustomDateType"
update="true"
insert="true"
column="BIRTH_DATE"
not-null="true"
/>

<property
name="gender"
type="string"
update="true"
insert="true"
column="GENDER"
not-null="true"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-FamilyMember.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


    Top
     Profile  
     
     Post subject:
    PostPosted: Wed Feb 11, 2004 12:37 pm 
    Hibernate Team
    Hibernate Team

    Joined: Sun Sep 14, 2003 3:54 am
    Posts: 7256
    Location: Paris, France
    Read the FAQ and doc on unsaved-value and assigned generator

    _________________
    Emmanuel


    Top
     Profile  
     
     Post subject:
    PostPosted: Wed Feb 11, 2004 3:27 pm 
    Newbie

    Joined: Tue Feb 10, 2004 4:31 pm
    Posts: 3
    I attempted to use the unsaved-value with different settings as well as having MySQL 'identity' generate the PK with no luck. Could you give me a little more info as to where I might find a solution in the docs.

    Thanks


    Top
     Profile  
     
     Post subject:
    PostPosted: Thu Feb 12, 2004 9:06 am 
    Hibernate Team
    Hibernate Team

    Joined: Sun Sep 14, 2003 3:54 am
    Posts: 7256
    Location: Paris, France
    if your stuck with assigned generator, reread the doc and the FAQ, it's pretty well explained. This is a key feature of Hibernate, you must understand that.

    Using identity generator, it shoud work.

    In FamilyMember mapping

    [code] <id
    name="id"
    column="FAMILY_MEMBER_ID"
    type="int" unsaved-value="null"
    >
    <generator class="identity">
    </generator>
    </id> [code]

    in your table, FAMILY_MEMBER_ID must be an identity

    In FamilyMember id should be Integer (or Long). If you use int (or long) set unsaved-value=0[/code]

    _________________
    Emmanuel


    Top
     Profile  
     
     Post subject:
    PostPosted: Thu Feb 12, 2004 10:42 am 
    Newbie

    Joined: Tue Feb 10, 2004 4:31 pm
    Posts: 3
    Read it. Got it. and Thanks.


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