-->
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: Why update Query is called; but i want insert
PostPosted: Tue Aug 31, 2004 5:22 am 
Newbie

Joined: Wed Aug 25, 2004 10:35 am
Posts: 3
Hi
when i am going to insert rows in ManagmentAlert table some rows also need to be insert in the AlertRecepient table . But some how the update query is called but not the insert query for the AlertReceipient Table
Can any one can help me to tell what i am doing wrong


Hibernate version:
2.1
Mapping documents:
<?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>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="alert.management_alert.ManagementAlert"
table="management_alert"
>


<id
name="managementAlertId"
type="java.lang.Integer"
column="MANAGEMENT_ALERT_ID"

>
<generator class="increment" />
</id>

<property
name="subject"
type="java.lang.String"
column="SUBJECT"
length="50"
/>
<property
name="content"
type="java.lang.String"
column="CONTENT"
length="2147483647"
/>
<property
name="generatedOn"
type="java.util.Date"
column="GENERATED_ON"
length="14"
/>
<property
name="showFrom"
type="java.util.Date"
column="SHOW_FROM"
length="19"
/>
<property
name="showTill"
type="java.util.Date"
column="SHOW_TILL"
length="19"
/>

<!-- associations -->
<!-- bi-directional one-to-many association to AlertRecipient -->
<set
name="alertRecipients"
lazy="true"
inverse="true"
cascade="save-update"
>
<key>
<column name="MANAGEMENT_ALERT_ID" />
</key>
<one-to-many
class="alert.management_alert.AlertRecipient"
/>
</set>
<!-- bi-directional many-to-one association to Employee -->
<many-to-one
name="employee"
class="employee.Employee"
not-null="true"
>
<column name="EMPLOYEE_ID" />
</many-to-one>

</class>
</hibernate-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>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="alert.management_alert.AlertRecipient"
table="alert_recipient"
>


<composite-id name="comp_id" class="alert.management_alert.AlertRecipientPK">
<!-- bi-directional many-to-one association to ManagementAlert -->
<key-many-to-one
name="managementAlert"
class="alert.management_alert.ManagementAlert"
>
<column name="MANAGEMENT_ALERT_ID" />
</key-many-to-one>
<!-- bi-directional many-to-one association to Employee -->
<key-many-to-one
name="employee"
class="employee.Employee"
>
<column name="EMPLOYEE_ID" />
</key-many-to-one>
</composite-id>

<property
name="alertViewed"
type="java.util.Date"
column="ALERT_VIEWED"
length="19"
/>
<property
name="alertDeleted"
type="java.util.Date"
column="ALERT_DELETED"
length="19"
/>

<!-- associations -->
<!-- bi-directional many-to-one association to GroupList -->
<many-to-one
name="groupList"
class="group.GroupList"
not-null="true"
>
<column name="GROUP_ID" />
</many-to-one>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
set.add(alertRecipient);
ManagementAlert m = new ManagementAlert("Subject " , "nasir is content" , date,date,date, emp,set);

tx = session.beginTransaction();

session.save(m);
tx.commit();

Full stack trace of any exception that occurs:
14:14:46,203 INFO [STDOUT] Hibernate: insert into management_alert (SUBJECT, CO
NTENT, GENERATED_ON, SHOW_FROM, SHOW_TILL, EMPLOYEE_ID, MANAGEMENT_ALERT_ID) val
ues (?, ?, ?, ?, ?, ?, ?)
14:14:46,250 INFO [STDOUT] Hibernate: update alert_recipient set ALERT_VIEWED=?
, ALERT_DELETED=?, GROUP_ID=? where MANAGEMENT_ALERT_ID=? and EMPLOYEE_ID=?
14:14:46,281 ERROR [SessionImpl] Could not synchronize database state with sessi
on
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:122)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2368)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.j
ava:61)
at alert.management_alert.Management_Alert_DAO.save_Management_Alert(Man
agement_Alert_DAO.java:79)
at alert.management_alert.Management_Alert_Session_Bean.save_M_A(Managem
ent_Alert_Session_Bean.java:220)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(S
tatelessSessionContainer.java:683)
Name and version of the database you are using:
My SQL 4.0
Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2004 5:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is just the usual problem where, for a composite-id class, Hibernate cannot distingiush between new and detached objects. Refer to the doco for more information.

Easiest solution: add a <version> or <timestamp> property.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2004 6:10 am 
Newbie

Joined: Wed Aug 25, 2004 10:35 am
Posts: 3
can you help me by giving some code example. By changing my code where should i change the my code
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2004 10:37 am 
Newbie

Joined: Fri Aug 27, 2004 10:36 am
Posts: 8
Does Adding <version> or <time-stamp> property mean Adding a column in Database and keep all data in database with different version or timestamp?

Any other ways?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 31, 2004 10:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, use Interceptor.isUnsaved(), as per the documentation.


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.