-->
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: probably bug in bulk delete
PostPosted: Mon Jan 09, 2006 12:41 pm 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
Hello, I made a small test case to demonstrate what I think is a bug in bulk delete. Before I file a bug in Jira, could someone please verify if I'm doing something wrong or if it is really a bug?

Hibernate version: 3.1

Mapping documents:
Code:
<hibernate-mapping package='com.csg.pmnet.se.model' default-access="field" default-cascade="all">

    <class name='T1' table='se_t1'>
        <id name='id'/>
        <set name='t2s' inverse="true">
            <key column='t1'/>
            <one-to-many class='T2'/>
        </set>
    </class>
   
    <class name='T2' table='se_t2'>
        <id name='id'/>
        <many-to-one name='t1' class='T1'/>
    </class>
   
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
        s.createQuery("from T1 t1 where size(t1.t2s)=0").list();
        s.createQuery("delete from T1 t1 where size(t1.t2s)=0").executeUpdate();


Name and version of the database you are using:
Oracle 9.2

The generated SQL (show_sql=true):
Code:
select t1x0_.id as id0_ from pms.se_t1 t1x0_ where (select count(t2s1_.t1) from pms.se_t2 t2s1_ where t1x0_.id=t2s1_.t1)=0
delete from pms.se_t1 where (select count(t2s1_.t1) from pms.se_t2 t2s1_ where id=t2s1_.t1)=0


Note the difference between the select and the delete statement: the select statement has a qualified id column in the subquery (.. where t1x0_.id=....), the delete does not. The select statement does the right thing.

In my case, since both tables have a column named id, the delete statement is wrong in that it takes the id column from the se_t2 table instead of the se_t1 table, obviously with a wrong result (it tries to delete ALL records which is prevented by a foreign key constraint).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 4:55 am 
Regular
Regular

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Zürich
Hello, just one last try to get your attention before I finally file this as a bug in Jira. Did anyone from the Hibernate team have time to have a look at my post?

I made my own work-around by modifying the tables column name, so the unqualified column name no longer hurts and now refers to the correct table.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 5:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, Oracle does not support table aliases in the delete clause. So I guess the correct SQL is this, eliminating the irrelevant schema names:

Code:
delete from se_t1 where (select count(t2s1_.t1) from se_t2 t2s1_ where se_t1.id=t2s1_.t1)=0


Sure, submit to JIRA.


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.