-->
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: Exception when trying to save object with one-to-many relati
PostPosted: Tue Mar 16, 2004 1:39 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
I have 2 classes:
Code:
<hibernate-mapping package="com.bertrams.berteShop.domain">
    <class name="OrderHeader" table="REORDH">
    <id name="id" type="long" unsaved-value="0">
      <column name="RHORNO" sql-type="long" not-null="true"/>
      <generator class="assigned"/>
   </id>

   <map name="orderItems">
           <key column="ODORNO"/>
           <index column="ODISBN" type="string"/>
              <one-to-many class="OrderItem"/>
   </map>
    </class>
</hibernate-mapping>

<hibernate-mapping package="com.bertrams.berteShop.domain">
    <class name="OrderItem" table="REORDL">
   <composite-id name="id" class="OrderItemKey">
      <key-property name="number" type="long" column="ODORNO"/>
      <key-property name="customer" type="int" column="ODCUST"/>
      <key-property name="branch" type="int" column="ODBRCH"/>
      <key-property name="consumerId" type="string" column="ODCNSM"/>       
      <key-property name="isbn" type="string" column="ODISBN"/>       
   </composite-id>
    </class>
</hibernate-mapping>


when i try to save OrderHeader i see 2 sqls:
first: insert into REORDH.....
seconde: update REORDL....
but then there is an exception:

Code:
17:30:22,812 DEBUG BatcherImpl:241 - preparing statement
17:30:22,844 DEBUG LongType:46 - binding '111111' to parameter: 1
17:30:22,844 DEBUG Cascades:331 - id unsaved-value strategy NONE
17:30:22,844 DEBUG LongType:46 - binding '111111' to parameter: 3
17:30:22,844 DEBUG IntegerType:46 - binding '1111111' to parameter: 4
17:30:22,844 DEBUG IntegerType:46 - binding '1' to parameter: 5
17:30:22,906 ERROR SessionImpl:2343 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)


Any idea why update sql and not insert to REORDL and why there is exception?

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 1:49 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
seeing your previous post and this one, it seems your hibernate session management is not good


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 2:02 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
delpouve wrote:
seeing your previous post and this one, it seems your hibernate session management is not good


but it is all happening in one session:
Code:
Session s = sessionFactory.openSession();
Transaction t = s.beginTransaction();
s.save(order);
t.commit();
s.close();


I thought by usin openSession i always get a new session.

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 2:04 pm 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
delpouve wrote:
seeing your previous post and this one, it seems your hibernate session management is not good


When i put inverse="true" on the map the header is saved but not the items.

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 16, 2004 2:06 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
just take one hour to configure servletFilter, remove all session.close() (you may need to force it again in some cases) from your app, and you'll see many bugs will dissappear


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.