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: net.sf.hibernate.HibernateException: Batch update row count
PostPosted: Wed Dec 29, 2004 3:46 pm 
Newbie

Joined: Sun Nov 21, 2004 6:20 pm
Posts: 11
Hi,

I want to map a One-To-Many Association between the Entity Question and the Entity Options. One question can have many options and one option can only belong to one Question. The primary key of Options consists of the Option_id and the Question_id, where the latter is a foreign
key to Question.

I wrote the following two mappings for Options and Question, which generated valid DDL using the Hibernate-SchemaUpdate Tool.

<hibernate-mapping>
<class name="de.ryll.hibernate.Options"
table="Options">
<composite-id name="id"
class="de.ryll.hibernate.OptionIdentifyer">
<key-property name="option_id" column="option_id"
type="integer"/>
<key-many-to-one name="question_id" class="de.ryll.hibernate.Question" column="question_id"/>
</composite-id>
<property name="option_text" column="option_text" type="string" not-null="true"/>
</class>
</hibernate-mapping>


<hibernate-mapping>
<class name="de.ryll.hibernate.Question"
table="Question">
<id name="question_id" column="question_id" type="integer">
<generator class="increment"/>
</id>
<property name="question_text" column="question_text" type="string" not-null="true"/>
<set name="options">
<key column = "question_id"/>
<one-to-many class="de.ryll.hibernate.Options"/>
</set>
</class>
</hibernate-mapping>

When I want to save a question along with its options like this:
session = HibernateUtil.currentSession();
tx = session.beginTransaction();
Question q = new Question();
q.setQuestion_text("Who shall be the president?");
Set options = new HashSet();
options.add((Options) new Options(new OptionIdentifyer(new Integer(1), q), "Bush"));
options.add((Options) new Options(new OptionIdentifyer(new Integer(2), q), "Kerry"));
q.setOptions((Set)options);
session.save((Question) obj);
tx.commit();
HibernateUtil.closeSession();

...I get the following Exceptions:

21:49:28,529 INFO SettingsFactory:106 - Use JDBC3 getGeneratedKeys(): false
21:49:28,529 INFO SettingsFactory:109 - Optimize cache for minimal puts: false
21:49:28,529 INFO SettingsFactory:118 - Query language substitutions: {}
21:49:28,529 INFO SettingsFactory:129 - cache provider: net.sf.hibernate.cache.EhCacheProvider
21:49:28,559 INFO Configuration:1116 - instantiating and configuring caches
21:49:29,170 INFO SessionFactoryImpl:118 - building session factory
21:49:29,771 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured

net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2375)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at de.ryll.hibernate.test.HibTool.createExampleData(HibTool.java:219)
at de.ryll.hibernate.test.HibTool.main(HibTool.java:91)
21:49:30,002 ERROR SessionImpl:2379 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2375)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at de.ryll.hibernate.test.HibTool.createExampleData(HibTool.java:219)
at de.ryll.hibernate.test.HibTool.main(HibTool.java:91)


*************************
What is my mistake?? ARE THE HBM-MAPPINGS CORRECT??? I have not implemented equals() and
hashCode() in the class OptionsIdentifyer - may this be the problem?? If yes, how would you
implement these methods...

It would be very great if anybody helps me a little bit...THANK YOU.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 5:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
did you check the FAQ?

_________________
Emmanuel


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.