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.  [ 4 posts ] 
Author Message
 Post subject: Saving multible objects inside one session.
PostPosted: Tue Dec 05, 2006 10:12 am 
Newbie

Joined: Tue Nov 28, 2006 3:24 am
Posts: 11
Hi!

I'm trying to save multible objects inside on session.

inside A.hbm.xml file I have defined
Code:
<set name="bs" table="B" inverse="true" cascade="all">
              <key column="A_id" />
               <one-to-many class="persistence.B" />
       </set>

and similarly for class C


in B and C.hbm.xml
Code:
<many-to-one name="a" class="persistence.A" column="A_id"/>



below is the code in class A
Code:


Set<B> bs;
Set<C> cs;

public void save(Session session){

      Transaction transaction = session.beginTransaction();
      session.save(this);
      transaction.commit();
      
      for (B b : bs) {
         b.save(session);
      }
      
      for (C c : cs) {
         c.save(session);
      }

   }


and blow is the code for class B and C, save-method in both is the same
Code:
public void save(Session) {
     Transaction transaction = session.beginTransaction();
     session.save(this);
     transaction.commit();
}


Hibernate version:
3.2.0 GA

Now I'm getting
Code:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
   at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
   at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
   at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at persistence.A.save(A.java:55)


What is the best solution saving tree of objects?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 11:35 am 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
Since you have the set of B's and C's defined with cascade="all", you only need to save the A object. Doing this will cascade the saves to all of the B's and C's that it contains. You may want to consider using cascade="all-delete-orphan" for the one-to-many's.

_________________
-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 11:44 am 
Newbie

Joined: Tue Nov 28, 2006 3:24 am
Posts: 11
Yes I tried that in first. but it didn't work out, I got almost the same exception:

Code:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
   at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
   at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
   at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at persistencetest.HibernatePluginTestAction.execute(HibernatePluginTestAction.java:151)


The error happens in both cases in
Code:
transaction.commit();

in the first example execution doesn't make the call
Code:
b.save(session);
but stops before.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 3:53 am 
Newbie

Joined: Tue Nov 28, 2006 3:24 am
Posts: 11
Hi again,

the problem tracked down to the PostgreSQLs JDBC-driver. The driver is downloaded from http://www.postgresql.org/ and it's the right version of it. So it leaves us two options, Hibernate uses the driver in a wrong way or the driver is broken.


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