-->
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.  [ 12 posts ] 
Author Message
 Post subject: Assigned identifier in Parent Child relationship
PostPosted: Fri Nov 21, 2003 5:15 pm 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
I am trying to use assigned identifier for a parent and child mapping with unsaved-value=any and i create parent. It works fine inserting parent and child in the tables. Now when i try to update the parent with the same mapping it doesnt work. I went thorugh section 8.4 of the reference documentation but couldnt figure out whether it can help me or not. Please help if someone has implemented it.
Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 5:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you use an assigned id, and have no version property, Hibernate has no way to decide if the object already exists in the database. So either cascade save or casade update is impossible.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 6:00 pm 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
Gavin, how can i use version property with assigned identifier ? It is a limitation that i have to use assigned identifier. Please help.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 7:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
<class ..>
..
<version
column="version_column"
name="propertyName"
type="typename"
/>
...

(section 4.1.7)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 10:00 am 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
After putting the version for the column the hibernat doesnt create the parent and child. My test code is still same but change for version is done in mapping file. Am i doing something worng there in the mapping file ?
I am sending the stack trace also, nothing happens after the end point in the stack trace.

mapping file 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.contract.business.domain.user.Parent" table="T_PARENT">
<id name="_id" column="ID" type="integer" unsaved-value="any">
<generator class="assigned"/>
</id>
<version column="ID" name="_id" type="integer"/>
<property name="_text" column="NAME"/>
<bag name="_child" inverse="true" cascade="all">
<key column="PARENT_ID"/>
<one-to-many class="com.bunge.bgm.contract.business.domain.user.Child"/>
</bag>
</class>
</hibernate-mapping>

and the stack trace is :
08:02:21,262 INFO Environment:432 - Hibernate 2.1 beta 5
08:02:21,278 INFO Environment:466 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.jndi.class=com.ibm.websphere.naming.WsnInitialContextFactory, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.jndi.url=iiop://localhost:2809, 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=net.sf.hibernate.test, net.sf.hibernate.eg, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=BGM_CONTRACTS, hibernate.connection.url=jdbc:oracle:thin:@10.25.39.138:1521:BGMIT, hibernate.show_sql=false, hibernate.connection.password=BGM_CONTRACTS, hibernate.statement_cache.size=0, hibernate.connection.pool_size=1}
08:02:21,278 INFO Environment:480 - using java.io streams to persist binary types
08:02:21,294 INFO Environment:481 - using CGLIB reflection optimizer
08:02:21,294 INFO Configuration:303 - Mapping resource: com/bunge/bgm/contract/business/domain/user/Child.hbm.xml
08:02:21,403 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
08:02:21,403 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
08:02:21,622 INFO Binder:198 - Mapping class: com.bunge.bgm.contract.business.domain.user.Child -> T_CHILD
08:02:21,762 DEBUG Binder:410 - Mapped property: _id -> CHILD_ID, type: integer
08:02:21,794 DEBUG Binder:410 - Mapped property: _text -> CHILD_NAME, type: string
08:02:21,809 DEBUG Binder:410 - Mapped property: _parent -> PARENT_ID, type: com.bunge.bgm.contract.business.domain.user.Parent
08:02:21,809 INFO Configuration:303 - Mapping resource: com/bunge/bgm/contract/business/domain/user/Parent.hbm.xml
08:02:21,809 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
08:02:21,809 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
08:02:21,840 INFO Binder:198 - Mapping class: com.bunge.bgm.contract.business.domain.user.Parent -> T_PARENT
08:02:21,840 DEBUG Binder:410 - Mapped property: _id -> ID, type: integer
08:02:21,840 DEBUG Binder:410 - Mapped property: _id -> ID, type: integer
08:02:21,840 DEBUG Binder:410 - Mapped property: _text -> NAME, type: string
08:02:21,887 DEBUG Binder:410 - Mapped property: _child, type: java.util.Collection
08:02:21,887 INFO Configuration:563 - processing one-to-many association mappings
08:02:21,887 DEBUG Binder:1249 - Second pass for collection: com.bunge.bgm.contract.business.domain.user.Parent._child
08:02:21,887 INFO Binder:1074 - Mapping collection: com.bunge.bgm.contract.business.domain.user.Parent._child -> T_CHILD
08:02:21,887 DEBUG Binder:1261 - Mapped collection key: PARENT_ID, one-to-many: com.bunge.bgm.contract.business.domain.user.Child
08:02:21,887 INFO Configuration:572 - processing one-to-one association property references
08:02:21,887 INFO Configuration:597 - processing foreign key constraints
08:02:21,887 DEBUG Configuration:607 - resolving reference to class: com.bunge.bgm.contract.business.domain.user.Parent
08:02:21,934 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.OracleDialect
08:02:21,950 INFO SettingsFactory:62 - Use outer join fetching: true
08:02:21,950 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
08:02:21,950 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
08:02:22,012 INFO DriverManagerConnectionProvider:71 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@10.25.39.138:1521:BGMIT
08:02:22,012 INFO DriverManagerConnectionProvider:72 - connection properties: {user=BGM_CONTRACTS, password=BGM_CONTRACTS}
08:02:22,028 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (use of process level read-write cache is not recommended)
08:02:22,028 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
08:02:22,028 DEBUG DriverManagerConnectionProvider:94 - opening new JDBC connection
08:02:23,153 DEBUG DriverManagerConnectionProvider:100 - created connection to: jdbc:oracle:thin:@10.25.39.138:1521:BGMIT, Isolation Level: 2
08:02:23,169 DEBUG DriverManagerConnectionProvider:114 - returning connection to pool, pool size: 1
08:02:23,169 INFO SettingsFactory:89 - Use scrollable result sets: true
08:02:23,169 INFO SettingsFactory:99 - Query language substitutions: {no='N', true=1, yes='Y', false=0}
08:02:23,169 INFO SettingsFactory:110 - cache provider: net.sf.hibernate.cache.JCSCacheProvider
08:02:23,184 INFO Configuration:990 - instantiating and configuring caches
08:02:23,340 INFO SessionFactoryImpl:115 - building session factory
08:02:23,340 DEBUG SessionFactoryImpl:121 - 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;C:\BGMIT\apps\Contract_Service\build\classes\hibernate.properties, 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, file.encoding=Cp1252, java.specification.version=1.4, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, java.class.path=C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\eclipse\plugins\com.cortexeb.tools.clover_1.1.2\clover-eclipse.jar;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\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\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\servlet.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:\hibernate-2.1\lib\ant.jar;C:\hibernate-2.1\lib\c3p0.jar;C:\hibernate-2.1\lib\cglib-asm.jar;C:\hibernate-2.1\lib\connector.jar;C:\hibernate-2.1\lib\jaas.jar;C:\hibernate-2.1\lib\jcs.jar;C:\hibernate-2.1\lib\jdbc2_0-stdext.jar;C:\hibernate-2.1\lib\jgroups.jar;C:\hibernate-2.1\lib\jta.jar;C:\hibernate-2.1\lib\odmg.jar;C:\hibernate-2.1\lib\optional.jar;C:\hibernate-2.1\lib\oscache.jar;C:\hibernate-2.1\lib\proxool.jar;C:\hibernate-2.1\lib\swarmcache.jar;C:\hibernate-2.1\lib\xalan.jar;C:\hibernate-2.1\lib\xerces.jar;C:\hibernate-2.1\lib\xml-apis.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\runtime.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\namingclient.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\wssec.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\sas.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\ecutils.jar;Z:\axis\axis.jar;Z:\axis\commons-discovery.jar;C:\BGMIT\apps\Contract_Web\lib\BGMFramework.jar;C:\BGMIT\apps\Contract_Web\lib\BGMDataHandlers.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\optionalLibraries\Apache\Struts\1.1\struts.jar;Z:\lib\saaj.jar;C:\hibernate-2.1\hibernate2.jar;Z:\BGM_EJB_ServiceFacade.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\naming.jar, user.name=crvashi, 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_01\jre, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.connection.url=jdbc:oracle:thin:@10.25.39.138:1521:BGMIT, 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_01, 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=0, hibernate.jndi.class=com.ibm.websphere.naming.WsnInitialContextFactory, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.cpu.isalist=pentium i486 i386}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 10:24 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<id name="_id" column="ID" type="integer" unsaved-value="any">
<generator class="assigned"/>
</id>
<version column="ID" name="_id" type="integer"/>


Version column (and property) must be mapped on a seperate column and be managed by Hibernate.
Code:
<version column="column" name="_column" type="integer"/>


Whatever, this is the child mapping that matters. Hibernate will do the following

Code:
update parent
check cascade
saveOrUpdate() each child (if not previously saved or updated).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 10:54 am 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
i added one more column to the parent table and changed the mapping file also. But still it is not working. I dont know what i m missing. Here is parent.hbm.xml :
<?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.contract.business.domain.user.Parent" table="T_PARENT">
<id name="_id" column="ID" type="integer" unsaved-value="any">
<generator class="assigned"/>
</id>
<version column="PARENT_COLUMN" name="_parentColumn" type="integer"/>

<property name="_text" column="NAME"/>
<bag name="_child" inverse="true" cascade="all">
<key column="PARENT_ID"/>
<one-to-many class="com.bunge.bgm.contract.business.domain.user.Child"/>
</bag>
</class>
</hibernate-mapping>
<!-- parsed in 2375ms -->

and child.hbm.xml 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.contract.business.domain.user.Child" table="T_CHILD">
<id name="_id" column="CHILD_ID" type="integer" unsaved-value="any">
<generator class="assigned"/>
</id>
<!--<version column="CHILD_COLUMN" name="_childColumn" type="integer"/> -->

<property name="_text" column="CHILD_NAME"/>
<many-to-one name="_parent" column="PARENT_ID" not-null="true"/>
</class>
</hibernate-mapping>
<!-- parsed in 0ms -->

When i create the parent parent it creates the child also. Here is the stack trace :
09:45:57,011 DEBUG SessionFactoryImpl:187 - instantiated session factory
09:45:57,105 DEBUG SessionImpl:478 - opened session
09:45:57,105 DEBUG JDBCTransaction:36 - begin
09:45:57,105 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
09:45:57,105 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
09:45:57,120 DEBUG SessionImpl:735 - saving [com.bunge.bgm.contract.business.domain.user.Parent#1]
09:45:57,120 DEBUG Cascades:356 - processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:45:57,120 DEBUG Cascades:364 - done processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:45:57,136 DEBUG SessionImpl:2808 - Wrapped collection in role: com.bunge.bgm.contract.business.domain.user.Parent._child
09:45:57,152 DEBUG Cascades:356 - processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:45:57,152 DEBUG Cascades:381 - cascading to collection: com.bunge.bgm.contract.business.domain.user.Parent._child
09:45:57,152 DEBUG Cascades:105 - cascading to saveOrUpdate()
09:45:57,152 DEBUG Cascades:255 - unsaved-value strategy ANY
09:45:57,152 DEBUG SessionImpl:1291 - saveOrUpdate() unsaved instance
09:45:57,152 DEBUG SessionImpl:735 - saving [com.bunge.bgm.contract.business.domain.user.Child#1]
09:45:57,152 DEBUG Cascades:364 - done processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:45:57,152 DEBUG JDBCTransaction:54 - commit
09:45:57,167 DEBUG SessionImpl:2242 - flushing session
09:45:57,167 DEBUG Cascades:356 - processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:45:57,167 DEBUG Cascades:381 - cascading to collection: com.bunge.bgm.contract.business.domain.user.Parent._child
09:45:57,167 DEBUG Cascades:105 - cascading to saveOrUpdate()
09:45:57,167 DEBUG SessionImpl:1277 - saveOrUpdate() persistent instance
09:45:57,167 DEBUG Cascades:364 - done processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:45:57,167 DEBUG SessionImpl:2353 - Flushing entities and processing referenced collections
09:45:57,167 DEBUG SessionImpl:2838 - Collection found: [com.bunge.bgm.contract.business.domain.user.Parent._child#1], was: [<unreferenced>]
09:45:57,183 DEBUG SessionImpl:2680 - Processing unreferenced collections
09:45:57,183 DEBUG SessionImpl:2691 - Scheduling collection removes/(re)creates/updates
09:45:57,183 DEBUG SessionImpl:2254 - Flushed: 2 insertions, 0 updates, 0 deletions to 2 objects
09:45:57,183 DEBUG SessionImpl:2259 - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
09:45:57,183 DEBUG Printer:74 - listing entities:
09:45:57,198 DEBUG Printer:81 - com.bunge.bgm.contract.business.domain.user.Child{_parent=Parent#1, _id=1, _text=Child2}
09:45:57,198 DEBUG Printer:81 - com.bunge.bgm.contract.business.domain.user.Parent{_id=1, _child=[Child#1], _parentColumn=0, _text=Parent2}
09:45:57,198 DEBUG SessionImpl:2291 - executing flush
09:45:57,198 DEBUG EntityPersister:508 - Inserting entity: [com.bunge.bgm.contract.business.domain.user.Parent#1]
09:45:57,198 DEBUG EntityPersister:509 - Version: 0
09:45:57,198 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
09:45:57,214 DEBUG BatcherImpl:226 - prepared statement get: insert into BGM_COMPONENTS.T_PARENT (PARENT_COLUMN, NAME, ID) values (?, ?, ?)
09:45:57,214 DEBUG BatcherImpl:232 - preparing statement
09:45:57,245 DEBUG EntityPersister:398 - Dehydrating entity: [com.bunge.bgm.contract.business.domain.user.Parent#1]
09:45:57,292 DEBUG EntityPersister:508 - Inserting entity: [com.bunge.bgm.contract.business.domain.user.Child#1]
09:45:57,308 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
09:45:57,308 DEBUG BatcherImpl:245 - closing statement
09:45:57,308 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
09:45:57,308 DEBUG BatcherImpl:226 - prepared statement get: insert into BGM_COMPONENTS.T_CHILD (CHILD_NAME, PARENT_ID, CHILD_ID) values (?, ?, ?)
09:45:57,308 DEBUG BatcherImpl:232 - preparing statement
09:45:57,308 DEBUG EntityPersister:398 - Dehydrating entity: [com.bunge.bgm.contract.business.domain.user.Child#1]
09:45:57,308 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
09:45:57,323 DEBUG BatcherImpl:245 - closing statement
09:45:57,323 DEBUG SessionImpl:2711 - post flush
09:45:57,323 DEBUG SessionImpl:508 - transaction completion
09:45:57,323 DEBUG SessionImpl:496 - closing session
09:45:57,323 DEBUG SessionImpl:3283 - disconnecting session
09:45:57,323 DEBUG DriverManagerConnectionProvider:114 - returning connection to pool, pool size: 1
09:45:57,323 DEBUG SessionImpl:508 - transaction completion

But while i update it fails, the stack trace is :
09:47:13,744 DEBUG SessionFactoryImpl:187 - instantiated session factory
09:47:13,854 DEBUG SessionImpl:478 - opened session
09:47:13,854 DEBUG JDBCTransaction:36 - begin
09:47:13,854 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
09:47:13,854 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
09:47:13,869 DEBUG SessionImpl:1349 - updating [com.bunge.bgm.contract.business.domain.user.Parent#1]
09:47:13,869 DEBUG SessionImpl:1153 - collection dereferenced while transient [com.bunge.bgm.contract.business.domain.user.Parent._child#1]
09:47:13,885 DEBUG Cascades:356 - processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:47:13,885 DEBUG Cascades:381 - cascading to collection: com.bunge.bgm.contract.business.domain.user.Parent._child
09:47:13,885 DEBUG Cascades:105 - cascading to saveOrUpdate()
09:47:13,901 DEBUG Cascades:255 - unsaved-value strategy ANY
09:47:13,901 DEBUG SessionImpl:1291 - saveOrUpdate() unsaved instance
09:47:13,901 DEBUG SessionImpl:735 - saving [com.bunge.bgm.contract.business.domain.user.Child#1]
09:47:13,916 DEBUG Cascades:364 - done processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:47:13,916 DEBUG JDBCTransaction:54 - commit
09:47:13,916 DEBUG SessionImpl:2242 - flushing session
09:47:13,932 DEBUG Cascades:356 - processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:47:13,932 DEBUG Cascades:381 - cascading to collection: com.bunge.bgm.contract.business.domain.user.Parent._child
09:47:13,932 DEBUG Cascades:105 - cascading to saveOrUpdate()
09:47:13,932 DEBUG SessionImpl:1277 - saveOrUpdate() persistent instance
09:47:13,932 DEBUG Cascades:364 - done processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
09:47:13,932 DEBUG SessionImpl:2353 - Flushing entities and processing referenced collections
09:47:13,947 DEBUG SessionImpl:2808 - Wrapped collection in role: com.bunge.bgm.contract.business.domain.user.Parent._child
09:47:13,947 DEBUG SessionImpl:2449 - Updating entity: [com.bunge.bgm.contract.business.domain.user.Parent#1]
09:47:13,947 DEBUG Versioning:26 - Incrementing: 0 to 1
09:47:13,947 DEBUG SessionImpl:2838 - Collection found: [com.bunge.bgm.contract.business.domain.user.Parent._child#1], was: [<unreferenced>]
09:47:13,963 DEBUG SessionImpl:2680 - Processing unreferenced collections
09:47:13,963 DEBUG SessionImpl:2691 - Scheduling collection removes/(re)creates/updates
09:47:13,963 DEBUG SessionImpl:2254 - Flushed: 1 insertions, 1 updates, 0 deletions to 2 objects
09:47:13,963 DEBUG SessionImpl:2259 - Flushed: 1 (re)creations, 0 updates, 1 removals to 1 collections
09:47:13,979 DEBUG Printer:74 - listing entities:
09:47:13,994 DEBUG Printer:81 - com.bunge.bgm.contract.business.domain.user.Child{_parent=Parent#1, _id=1, _text=Child1}
09:47:13,994 DEBUG Printer:81 - com.bunge.bgm.contract.business.domain.user.Parent{_id=1, _child=[Child#1], _parentColumn=1, _text=Parent1}
09:47:13,994 DEBUG SessionImpl:2291 - executing flush
09:47:13,994 DEBUG EntityPersister:508 - Inserting entity: [com.bunge.bgm.contract.business.domain.user.Child#1]
09:47:13,994 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
09:47:13,994 DEBUG BatcherImpl:226 - prepared statement get: insert into BGM_COMPONENTS.T_CHILD (CHILD_NAME, PARENT_ID, CHILD_ID) values (?, ?, ?)
09:47:13,994 DEBUG BatcherImpl:232 - preparing statement
09:47:14,026 DEBUG EntityPersister:398 - Dehydrating entity: [com.bunge.bgm.contract.business.domain.user.Child#1]
09:47:14,104 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
09:47:14,104 DEBUG BatcherImpl:245 - closing statement
09:47:14,119 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: ORA-00001: unique constraint (BGM_COMPONENTS.PK_CHILD) violated

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:523)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:498)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2340)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2294)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
at com.bunge.bgm.contract.business.domain.user.ParentMain.updateParent(ParentMain.java:68)
at com.bunge.bgm.contract.business.domain.user.ParentMain.main(ParentMain.java:96)
09:47:14,119 WARN JDBCExceptionReporter:38 - SQL Error: 1, SQLState: 23000
09:47:14,119 ERROR JDBCExceptionReporter:46 - ORA-00001: unique constraint (BGM_COMPONENTS.PK_CHILD) violated

09:47:14,119 ERROR JDBCExceptionReporter:38 - could not insert: [com.bunge.bgm.contract.business.domain.user.Child#1]
java.sql.SQLException: ORA-00001: unique constraint (BGM_COMPONENTS.PK_CHILD) violated

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:523)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:498)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2340)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2294)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
at com.bunge.bgm.contract.business.domain.user.ParentMain.updateParent(ParentMain.java:68)
at com.bunge.bgm.contract.business.domain.user.ParentMain.main(ParentMain.java:96)
09:47:14,119 ERROR SessionImpl:2302 - Could not synchronize database state with session
net.sf.hibernate.JDBCException: could not insert: [com.bunge.bgm.contract.business.domain.user.Child#1]
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:533)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:498)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2340)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2294)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
at com.bunge.bgm.contract.business.domain.user.ParentMain.updateParent(ParentMain.java:68)
at com.bunge.bgm.contract.business.domain.user.ParentMain.main(ParentMain.java:96)
Caused by: java.sql.SQLException: ORA-00001: unique constraint (BGM_COMPONENTS.PK_CHILD) violated

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:523)
... 8 more
09:47:14,135 DEBUG JDBCTransaction:73 - rollback
09:47:14,135 DEBUG SessionImpl:508 - transaction completion
09:47:14,135 DEBUG SessionImpl:496 - closing session
09:47:14,135 DEBUG SessionImpl:3283 - disconnecting session
09:47:14,135 DEBUG DriverManagerConnectionProvider:114 - returning connection to pool, pool size: 1
09:47:14,135 DEBUG SessionImpl:508 - transaction completion

I think i am still not able to do what is required to do cascade update. Here is my test class :

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;
import net.sf.hibernate.tool.hbm2ddl.SchemaExport;

import com.bunge.bgm.contract.business.domain.user.Parent;
import com.bunge.bgm.contract.business.domain.user.Child;

import java.util.*;

public class ParentMain {

private SessionFactory _sessions;

/**
*
* @throws HibernateException
*/
public void configure() throws HibernateException
{
_sessions = new Configuration()
.addClass(Child.class)
.addClass(Parent.class)
.buildSessionFactory();
}


/**
*
* @param id
* @param name
* @return
* @throws HibernateException
*/
public void createParent(Parent parent) throws HibernateException {
Session session = _sessions.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.save(parent);
tx.commit();
} catch (HibernateException he) {
if (tx != null)
tx.rollback();
throw he;
} finally {
session.close();
}
}

/**
*
* @param parent
* @throws HibernateException
*/
public void updateParent(Parent parent) throws HibernateException {
Session session = _sessions.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.update(parent);
tx.commit();
} catch (HibernateException he) {
if (tx != null)
tx.rollback();
throw he;
} finally {
session.close();
}
}

/**
*
* @param a
*/
public static void main(String a[]) {
try {
ParentMain m = new ParentMain();
m.configure();

Parent p = new Parent();
p.set_id(new Integer(1));
p.set_text("Parent1");

Collection c = new ArrayList();
Child child = new Child();
child.set_id(new Integer(1));
child.set_text("Child1");
child.set_parent(p);
c.add(child);
p.set_child(c);

//m.createParent(p);
m.updateParent(p);
}
catch (Exception e) {
}
}
}

Can you find something missin in any one of the files above. I am trying it but it is trying to create the child when the child should be updated. Thanks for all your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 11:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I assume that

(a) you are using Hibernate 2.1
(b) your version property is of nonprimitive type and is initialzed to a null value when the object is instantiated.

Now set unsaved-value="none".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 11:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
And uncomment
Code:
<!--<version column="CHILD_COLUMN" name="_childColumn" type="integer"/> -->


in your child class.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 12:36 pm 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
(a) you are using Hibernate 2.1
yes hibernate2.1 beta5
(b) your version property is of nonprimitive type and is initialzed to a null value when the object is instantiated.
beforehand i declared the version property as int primitive type and it was initialized to 0 by hibernate but now i made it to Integer type and again it is instantiated to 0 when object is instantiated.(Do i have to do something here on my own ?)

Set unsaved-value="none" for both parent and child.

And after doing the changes i created a parent and child and it worked fine. Now when i try to update the created parent and child it tries to insert the parent and throws the error. The stack trace is :
11:27:15,215 INFO Environment:432 - Hibernate 2.1 beta 5
11:27:15,231 INFO Environment:466 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.cglib.use_reflection_optimizer=true, hibernate.jndi.class=com.ibm.websphere.naming.WsnInitialContextFactory, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.jndi.url=iiop://localhost:2809, 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=net.sf.hibernate.test, net.sf.hibernate.eg, hibernate.proxool.pool_alias=pool1, hibernate.connection.username=BGM_CONTRACTS, hibernate.connection.url=jdbc:oracle:thin:@10.25.39.138:1521:BGMIT, hibernate.show_sql=false, hibernate.connection.password=BGM_CONTRACTS, hibernate.statement_cache.size=0, hibernate.connection.pool_size=1}
11:27:15,231 INFO Environment:480 - using java.io streams to persist binary types
11:27:15,247 INFO Environment:481 - using CGLIB reflection optimizer
11:27:15,247 INFO Configuration:303 - Mapping resource: com/bunge/bgm/contract/business/domain/user/Child.hbm.xml
11:27:15,825 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
11:27:15,825 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
11:27:16,059 INFO Binder:198 - Mapping class: com.bunge.bgm.contract.business.domain.user.Child -> T_CHILD
11:27:16,184 DEBUG Binder:410 - Mapped property: _id -> CHILD_ID, type: integer
11:27:16,184 DEBUG Binder:410 - Mapped property: _childColumn -> CHILD_COLUMN, type: integer
11:27:16,215 DEBUG Binder:410 - Mapped property: _text -> CHILD_NAME, type: string
11:27:16,231 DEBUG Binder:410 - Mapped property: _parent -> PARENT_ID, type: com.bunge.bgm.contract.business.domain.user.Parent
11:27:16,231 INFO Configuration:303 - Mapping resource: com/bunge/bgm/contract/business/domain/user/Parent.hbm.xml
11:27:16,231 DEBUG DTDEntityResolver:20 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
11:27:16,247 DEBUG DTDEntityResolver:29 - found http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
11:27:16,262 INFO Binder:198 - Mapping class: com.bunge.bgm.contract.business.domain.user.Parent -> T_PARENT
11:27:16,262 DEBUG Binder:410 - Mapped property: _id -> ID, type: integer
11:27:16,278 DEBUG Binder:410 - Mapped property: _parentColumn -> PARENT_COLUMN, type: integer
11:27:16,278 DEBUG Binder:410 - Mapped property: _text -> NAME, type: string
11:27:16,309 DEBUG Binder:410 - Mapped property: _child, type: java.util.Collection
11:27:16,309 INFO Configuration:563 - processing one-to-many association mappings
11:27:16,309 DEBUG Binder:1249 - Second pass for collection: com.bunge.bgm.contract.business.domain.user.Parent._child
11:27:16,309 INFO Binder:1074 - Mapping collection: com.bunge.bgm.contract.business.domain.user.Parent._child -> T_CHILD
11:27:16,309 DEBUG Binder:1261 - Mapped collection key: PARENT_ID, one-to-many: com.bunge.bgm.contract.business.domain.user.Child
11:27:16,309 INFO Configuration:572 - processing one-to-one association property references
11:27:16,309 INFO Configuration:597 - processing foreign key constraints
11:27:16,325 DEBUG Configuration:607 - resolving reference to class: com.bunge.bgm.contract.business.domain.user.Parent
11:27:16,372 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.OracleDialect
11:27:16,387 INFO SettingsFactory:62 - Use outer join fetching: true
11:27:16,387 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
11:27:16,387 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 1
11:27:16,465 INFO DriverManagerConnectionProvider:71 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@10.25.39.138:1521:BGMIT
11:27:16,465 INFO DriverManagerConnectionProvider:72 - connection properties: {user=BGM_CONTRACTS, password=BGM_CONTRACTS}
11:27:16,481 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (use of process level read-write cache is not recommended)
11:27:16,481 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
11:27:16,481 DEBUG DriverManagerConnectionProvider:94 - opening new JDBC connection
11:27:17,606 DEBUG DriverManagerConnectionProvider:100 - created connection to: jdbc:oracle:thin:@10.25.39.138:1521:BGMIT, Isolation Level: 2
11:27:17,622 DEBUG DriverManagerConnectionProvider:114 - returning connection to pool, pool size: 1
11:27:17,622 INFO SettingsFactory:89 - Use scrollable result sets: true
11:27:17,622 INFO SettingsFactory:99 - Query language substitutions: {no='N', true=1, yes='Y', false=0}
11:27:17,622 INFO SettingsFactory:110 - cache provider: net.sf.hibernate.cache.JCSCacheProvider
11:27:17,622 INFO Configuration:990 - instantiating and configuring caches
11:27:17,794 INFO SessionFactoryImpl:115 - building session factory
11:27:17,794 DEBUG SessionFactoryImpl:121 - 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;C:\BGMIT\apps\Contract_Service\build\classes\hibernate.properties, 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, file.encoding=Cp1252, java.specification.version=1.4, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, java.class.path=C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\eclipse\plugins\com.cortexeb.tools.clover_1.1.2\clover-eclipse.jar;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\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\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\servlet.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:\hibernate-2.1\lib\ant.jar;C:\hibernate-2.1\lib\c3p0.jar;C:\hibernate-2.1\lib\cglib-asm.jar;C:\hibernate-2.1\lib\connector.jar;C:\hibernate-2.1\lib\jaas.jar;C:\hibernate-2.1\lib\jcs.jar;C:\hibernate-2.1\lib\jdbc2_0-stdext.jar;C:\hibernate-2.1\lib\jgroups.jar;C:\hibernate-2.1\lib\jta.jar;C:\hibernate-2.1\lib\odmg.jar;C:\hibernate-2.1\lib\optional.jar;C:\hibernate-2.1\lib\oscache.jar;C:\hibernate-2.1\lib\proxool.jar;C:\hibernate-2.1\lib\swarmcache.jar;C:\hibernate-2.1\lib\xalan.jar;C:\hibernate-2.1\lib\xerces.jar;C:\hibernate-2.1\lib\xml-apis.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\runtime.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\namingclient.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\wssec.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\sas.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\ecutils.jar;Z:\axis\axis.jar;Z:\axis\commons-discovery.jar;C:\BGMIT\apps\Contract_Web\lib\BGMFramework.jar;C:\BGMIT\apps\Contract_Web\lib\BGMDataHandlers.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\optionalLibraries\Apache\Struts\1.1\struts.jar;Z:\lib\saaj.jar;C:\hibernate-2.1\hibernate2.jar;Z:\BGM_EJB_ServiceFacade.jar;C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1\runtimes\base_v5\lib\naming.jar, user.name=crvashi, 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_01\jre, sun.arch.data.model=32, hibernate.dialect=net.sf.hibernate.dialect.OracleDialect, hibernate.connection.url=jdbc:oracle:thin:@10.25.39.138:1521:BGMIT, 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_01, 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=0, hibernate.jndi.class=com.ibm.websphere.naming.WsnInitialContextFactory, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.cpu.isalist=pentium i486 i386}
11:27:18,372 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
11:27:18,372 DEBUG SessionFactoryObjectFactory:76 - registered: 8a990b1cf90e90f500f90e90f7d40000 (unnamed)
11:27:18,372 INFO SessionFactoryObjectFactory:82 - no JNDI name configured
11:27:18,372 DEBUG SessionFactoryImpl:187 - instantiated session factory
11:27:18,465 DEBUG SessionImpl:478 - opened session
11:27:18,465 DEBUG JDBCTransaction:36 - begin
11:27:18,465 DEBUG DriverManagerConnectionProvider:78 - total checked-out connections: 0
11:27:18,465 DEBUG DriverManagerConnectionProvider:84 - using pooled JDBC connection, pool size: 0
11:27:18,481 DEBUG SessionImpl:735 - saving [com.bunge.bgm.contract.business.domain.user.Parent#2]
11:27:18,481 DEBUG Cascades:356 - processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
11:27:18,497 DEBUG Cascades:364 - done processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
11:27:18,497 DEBUG Versioning:35 - Seeding: 0
11:27:18,497 DEBUG SessionImpl:2808 - Wrapped collection in role: com.bunge.bgm.contract.business.domain.user.Parent._child
11:27:18,512 DEBUG Cascades:356 - processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
11:27:18,512 DEBUG Cascades:381 - cascading to collection: com.bunge.bgm.contract.business.domain.user.Parent._child
11:27:18,528 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:27:18,528 DEBUG SessionImpl:1291 - saveOrUpdate() unsaved instance
11:27:18,528 DEBUG SessionImpl:735 - saving [com.bunge.bgm.contract.business.domain.user.Child#2]
11:27:18,528 DEBUG Versioning:35 - Seeding: 0
11:27:18,528 DEBUG Cascades:364 - done processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
11:27:18,528 DEBUG JDBCTransaction:54 - commit
11:27:18,528 DEBUG SessionImpl:2242 - flushing session
11:27:18,528 DEBUG Cascades:356 - processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
11:27:18,528 DEBUG Cascades:381 - cascading to collection: com.bunge.bgm.contract.business.domain.user.Parent._child
11:27:18,528 DEBUG Cascades:105 - cascading to saveOrUpdate()
11:27:18,544 DEBUG SessionImpl:1277 - saveOrUpdate() persistent instance
11:27:18,544 DEBUG Cascades:364 - done processing cascades for: com.bunge.bgm.contract.business.domain.user.Parent
11:27:18,544 DEBUG SessionImpl:2353 - Flushing entities and processing referenced collections
11:27:18,544 DEBUG SessionImpl:2838 - Collection found: [com.bunge.bgm.contract.business.domain.user.Parent._child#2], was: [<unreferenced>]
11:27:18,544 DEBUG SessionImpl:2680 - Processing unreferenced collections
11:27:18,544 DEBUG SessionImpl:2691 - Scheduling collection removes/(re)creates/updates
11:27:18,559 DEBUG SessionImpl:2254 - Flushed: 2 insertions, 0 updates, 0 deletions to 2 objects
11:27:18,559 DEBUG SessionImpl:2259 - Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
11:27:18,575 DEBUG Printer:74 - listing entities:
11:27:18,575 DEBUG Printer:81 - com.bunge.bgm.contract.business.domain.user.Child{_parent=Parent#2, _childColumn=0, _id=2, _text=Child3}
11:27:18,575 DEBUG Printer:81 - com.bunge.bgm.contract.business.domain.user.Parent{_id=2, _child=[Child#2], _parentColumn=0, _text=Parent3}
11:27:18,575 DEBUG SessionImpl:2291 - executing flush
11:27:18,575 DEBUG EntityPersister:508 - Inserting entity: [com.bunge.bgm.contract.business.domain.user.Parent#2]
11:27:18,575 DEBUG EntityPersister:509 - Version: 0
11:27:18,575 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
11:27:18,575 DEBUG BatcherImpl:226 - prepared statement get: insert into BGM_COMPONENTS.T_PARENT (PARENT_COLUMN, NAME, ID) values (?, ?, ?)
11:27:18,575 DEBUG BatcherImpl:232 - preparing statement
11:27:18,622 DEBUG EntityPersister:398 - Dehydrating entity: [com.bunge.bgm.contract.business.domain.user.Parent#2]
11:27:18,684 DEBUG BatcherImpl:199 - done closing: 0 open PreparedStatements, 0 open ResultSets
11:27:18,684 DEBUG BatcherImpl:245 - closing statement
11:27:18,700 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: ORA-00001: unique constraint (BGM_COMPONENTS.PK_PARENT) violated

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:523)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:498)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2340)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2294)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
at com.bunge.bgm.contract.business.domain.user.ParentMain.createParent(ParentMain.java:52)
at com.bunge.bgm.contract.business.domain.user.ParentMain.main(ParentMain.java:104)
11:27:18,700 WARN JDBCExceptionReporter:38 - SQL Error: 1, SQLState: 23000
11:27:18,700 ERROR JDBCExceptionReporter:46 - ORA-00001: unique constraint (BGM_COMPONENTS.PK_PARENT) violated

11:27:18,700 ERROR JDBCExceptionReporter:38 - could not insert: [com.bunge.bgm.contract.business.domain.user.Parent#2]
java.sql.SQLException: ORA-00001: unique constraint (BGM_COMPONENTS.PK_PARENT) violated

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:523)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:498)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2340)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2294)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
at com.bunge.bgm.contract.business.domain.user.ParentMain.createParent(ParentMain.java:52)
at com.bunge.bgm.contract.business.domain.user.ParentMain.main(ParentMain.java:104)
11:27:18,715 ERROR SessionImpl:2302 - Could not synchronize database state with session
net.sf.hibernate.JDBCException: could not insert: [com.bunge.bgm.contract.business.domain.user.Parent#2]
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:533)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:498)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2340)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2294)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
at com.bunge.bgm.contract.business.domain.user.ParentMain.createParent(ParentMain.java:52)
at com.bunge.bgm.contract.business.domain.user.ParentMain.main(ParentMain.java:104)
Caused by: java.sql.SQLException: ORA-00001: unique constraint (BGM_COMPONENTS.PK_PARENT) violated

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:523)
... 8 more
11:27:18,715 DEBUG JDBCTransaction:73 - rollback
11:27:18,715 DEBUG SessionImpl:508 - transaction completion
11:27:18,715 DEBUG SessionImpl:496 - closing session
11:27:18,715 DEBUG SessionImpl:3283 - disconnecting session
11:27:18,715 DEBUG DriverManagerConnectionProvider:114 - returning connection to pool, pool size: 1
11:27:18,715 DEBUG SessionImpl:508 - transaction completion

Still i get a feel that something is missing at my end. Is it related to unsaved-value attribute and its value "none" ? I dont know how does Hibernate comes to know about cascade updates for assigned identifiers.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 12:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Take a break and come back to it.

All you need to do is think about what Hibernate needs. Hibernate needs some way to judge if an object already exists in the database. When it finds on object in the object graph, it

(1) looks at the version property
if version==null INSERT
otherwise goto (2)
(2) looks at identifier value
if unsaved-value=none, it doesn't matter what the id value is, so UPDATE

its really not that magical


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 1:42 pm 
Beginner
Beginner

Joined: Wed Oct 22, 2003 11:26 am
Posts: 31
Thanks a lot for great help Hibernate Team.
Finally it cascade update worked for me for assigned identifier. There was one thing i was missing in my test method. I was creating parent and child object with the existing identifier in the table but i wasnt setting version property in the object created for testing. After i put the version property in the object and said session.update(). It worked.
Thanks once again to all of you.


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