-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problems with composite pattern
PostPosted: Tue May 11, 2004 11:43 am 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
I'm using hibernate version 2.1.3 and mySQL

My situation:

Abstract Class Component
|
|
Abstract Class CompositeComponent
extends Component
|
|
Class StdComposite extends CompositeComponent


And I also use the composite pattern.

When I type this into Java Code:

Component comp1 = new StdComposite("name","description");
Component comp2 = new StdComposite("name","description");
comp1.setParent((CompositeComponent) comp2); //=>setParent
...
//store it with hibernate on the usual way: session.save(comp1);

Hibernate gives following error message:





17:20:07,109 ERROR SessionImpl:2368 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:687)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:640)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2361)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)
at storage.HibernateStorage.Store(HibernateStorage.java:129)
at storage.HibernateStorage.main(HibernateStorage.java:177)
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:687)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:640)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2407)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2361)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2229)
at storage.HibernateStorage.Store(HibernateStorage.java:129)
at storage.HibernateStorage.main(HibernateStorage.java:177)




When I don't set the parent or the children, everything goes fine.

For completeness:

MAPPING:
<?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="logic.Component"
table="COMPONENT">

<id
name="id"
column="ID"
type="long"
unsaved-value="null">
<generator class="native"/>
</id>


<discriminator column="DISCRIMINATOR" type="string"/>

<property
name="name"
column="NAME"
not-null="false"
unique="true"
type="java.lang.String"/>

<property
name="description"
column="DESCRIPTION"
not-null="false"
unique="false"
type="java.lang.String"/>

<set
name="children"
inverse="true"
lazy="false"
cascade="save-update">
<key column="CHILDREN"/>
<one-to-many class="logic.Component"/>
</set>

<many-to-one
name="parent"
column="PARENT"
not-null="false"
cascade="save-update"
class="logic.Component"/>


<subclass
name="logic.CompositeComponent"
discriminator-value="composite"/>

<subclass
name="logic.StdComposite"
discriminator-value="stdcomposite"/>

<subclass
name="logic.ModelComposite"
discriminator-value="modelcomposite"/>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 6:09 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
try and use session.flush()

later, try set transient identity to -1
Code:
<id
name="id"
column="ID"
type="long"
unsaved-value="-1">
<generator class="native"/>
</id>


(remember to initialize the id value to -1 in the POJO as well)


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