-->
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.  [ 3 posts ] 
Author Message
 Post subject: Insert using hibernate having one to many relationship
PostPosted: Wed Feb 11, 2009 5:58 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 8:18 am
Posts: 35
I am going to insert two tables using hibernate having one to many relationship.

but the child table is not adding the row.

also not showing any exception.

can any help me how to do that?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2009 6:43 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Could you please post the code of both class and its mapping files.


Top
 Profile  
 
 Post subject: Re: Insert using hibernate having one to many relationship
PostPosted: Thu Feb 12, 2009 12:27 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2008 8:18 am
Posts: 35
I am able to insert in both parent and child table from application but when i am deleting from application, the child table is not deleted, it is throwing some exception. If i will delete the child table data from DB2 and then delete this data from application then it is working fine.

It is throwing the following exception when deleting from application

[2/12/09 21:34:34:629 IST] 3021d4b5 JDBCException W net.sf.hibernate.util.JDBCExceptionReporter SQL Error: -407, SQLState: 23502
[2/12/09 21:34:34:629 IST] 3021d4b5 JDBCException E net.sf.hibernate.util.JDBCExceptionReporter [IBM][CLI Driver][DB2/NT] SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2, TABLEID=2, COLNO=1" is not allowed. SQLSTATE=23502

[2/12/09 21:34:34:644 IST] 3021d4b5 JDBCException E net.sf.hibernate.util.JDBCExceptionReporter could not delete collection: [com.kroger.accounting.rem.bo.RentChange.interCompanyRentPayee#57126]
[2/12/09 21:34:34:660 IST] 3021d4b5 JDBCException E net.sf.hibernate.util.JDBCExceptionReporter TRAS0014I: The following exception was logged COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0407N Assignment of a NULL value to a NOT NULL column "TBSPACEID=2, TABLEID=2, COLNO=1" is not allowed. SQLSTATE=23502


I have used the following hbm files..

parent table configuration

<hibernate-mapping>
<class
name="com.kroger.accounting.rem.bo.RentChange"
table="RNT_CHG_HST"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="RNT_CHG_HST_ID"
type="long"
unsaved-value="0"
>
<generator class="native">
</generator>
</id>

<property
name="arrears"
type="java.lang.Boolean"
update="true"
insert="true"
column="ARR_FL"
/>

<property
name="effectiveDate"
type="java.sql.Date"
update="true"
insert="true"
column="RNT_CHG_EFF_DT"
/>

<property
name="oneTimePayDate"
type="java.sql.Date"
update="true"
insert="true"
column="OTM_PMT_DT"
/>

<property
name="endDate"
type="java.sql.Date"
update="true"
insert="true"
column="RNT_CHG_END_DT"
/>
<bag
name="interCompanyRentPayee"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
>

<key>
<column name="RNT_CHG_HST_ID"/>
</key>

<one-to-many
class="com.kroger.accounting.rem.bo.InterCompanyRent"
/>
</bag>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-RentChange.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>

And the child table configuration is

<?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>
<class
name="com.kroger.accounting.rem.bo.InterCompanyRent"
table="INT_CMP_RNT"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="INT_CMP_RNT_ID"
type="long"
unsaved-value="0"
>
<generator class="native">
</generator>
</id>

<many-to-one
name="rentChange"
class="com.kroger.accounting.rem.bo.RentChange"
cascade="none"
outer-join="auto"
update="false"
insert="false"
>
<column
name="RNT_CHG_HST_ID"
/>
</many-to-one>
<property
name="rentChangeId"
type="java.lang.Long"
update="true"
insert="true"
column="RNT_CHG_HST_ID"
/>

<property
name="interCompanyRentAmount"
type="java.math.BigDecimal"
update="true"
insert="true"
column="INT_CMP_RNT_AMT"
/>

<property
name="InterCompanyRemExpensiveAcNumber"
type="com.kroger.accounting.rem.util.TrimmedUppercaseString"
update="true"
insert="true"
column="INT_CMP_REM_ACC_NO"
/>

<property
name="InterCompanyRetExpensiveNumber"
type="com.kroger.accounting.rem.util.TrimmedUppercaseString"
update="true"
insert="true"
column="INT_CMP_RET_ACC_NO"
/>

<property
name="divisionId"
type="java.lang.Long"
update="true"
insert="true"
column="REM_DIV_ID"
/>




<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-RentChange.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


can you please help me how to resolve this issue.

Thanks.


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