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: