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.  [ 1 post ] 
Author Message
 Post subject: Error in delete parent child records - one-to-many scenario
PostPosted: Wed Aug 30, 2006 8:49 am 
Newbie

Joined: Thu Aug 17, 2006 8:13 am
Posts: 8
[b]Hibernate version:3.0[/b]

[b]Mapping documents:
1. Hibernate configuration file
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="player.hbm.xml"/>
<mapping resource="emp.hbm.xml"/>
<mapping resource="dept.hbm.xml"/>
</session-factory>
2. in [color=Orange][size=18]dept.hbm.xml[/size][/color]
<hibernate-mapping>
<class name="dept" table="dept">
<id name="deptno" column="DEPTNO" >
</id>
<property column="DNAME" name="dname" type="string" />
<property column="LOC" name="loc" type="string" />
<set name="[b]deptno"[/b] inverse="false" cascade="delete" lazy="false" >
<key column="DEPTNO" not-null="true" />
<one-to-many class="emp" />
</set>
</class>
</hibernate-mapping>
3. in [color=Orange][size=18]emp.hbm.xml[/size][/color]
<hibernate-mapping>
<class name="emp" table="tblemp">
<id name="empno" column="empno">
</id>
<property name="ename" type="string" />
<property name="deptno" type="integer" />
<property name="password" type="string" />
</class>
</hibernate-mapping>
[/b]

[b]Code between sessionFactory.openSession() and session.close():[/b]
Session session = factory.openSession();
int z=Integer.parseInt(req.getParameter("txtKey"));
int i= session.createQuery("delete from dept where deptno = "+z)
.executeUpdate();
tx.commit();
session.flush();
session.close();
[b]Full stack trace of any exception that occurs:[/b]
inverse="true" cascade="delete" for delete from ..

Hibernate: delete from dept where DEPTNO=20
2006-08-30 16:43:01,852 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Er
ror: 2292, SQLState: 23000>
2006-08-30 16:43:01,852 ERROR [org.hibernate.util.JDBCExceptionReporter] - ORA-0
2292: integrity constraint (SCOTT.FK_DEPT) violated - child record found
>
[b]error thrown to jsp[/b]
org.hibernate.exception.ConstraintViolationException: could not execute update query
org.hibernate.exception.ConstraintViolationException: could not execute update query at

org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74) at

org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at

org.hibernate.hql.ast.UpdateStatementExecutor.execute(UpdateStatementExecutor.java:99) at

org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:297) at

org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:871) at org.hibernate.impl.QueryImpl.....

[b]if i write delete-all-orphan inverse="false"[/b]


IN INIT()org.hibernate.MappingException: Unsupported cascade style: all-delete-orphans


[b]Name and version of the database you are using:[/b]
Oracle9i
table
DEPT : deptno number -(PK)
deptname varchar
loc-varchar
TBLEMP: empno -number-(pk)
ename-varchar
password -varchar
deptno- (fk) -DEPT Table
If i write on-delete-cascade here on table lable then everything ok and there is no need of writiing <set .. in dept.hbm.xml and emp.hbm.xml .
but if i will not mentioned on-delete-cascade on table lable then the problem comes.

[b]The generated SQL (show_sql=true):[/b]
Hibernate: delete from dept where DEPTNO=20
2006-08-30 16:43:01,852 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Er
ror: 2292, SQLState: 23000>
2006-08-30 16:43:01,852 ERROR [org.hibernate.util.JDBCExceptionReporter] - ORA-0
2292: integrity constraint (SCOTT.FK_DEPT) violated - child record found
>
Please help me in solving one-to-many problem.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.