-->
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.  [ 2 posts ] 
Author Message
 Post subject: Why so many SQL queries
PostPosted: Fri Sep 26, 2008 5:15 am 
Newbie

Joined: Fri Sep 26, 2008 4:45 am
Posts: 1
Hibernate entity manager version:3.3.2.GA

I have the following entities:
Code:
@Entity
public class Parent implements Serializable {
   @Id
   public long id;
   @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
   Set<Child> children;
}

@Entity
public class Child implements Serializable {
   @Id
   long id;
   @ManyToOne
   Parent parent;
}


and execute the following code

Code:
Parent parent = em.getReference(Parent.class, 1L);
em.remove(parent);
em.flush();

it generates SQL queries:

Code:
Hibernate: select parent0_.id as id35_0_ from Parent parent0_ where parent0_.id=?
Hibernate: select children0_.parent_id as parent2_1_, children0_.id as id1_, children0_.id as id20_0_, children0_.parent_id as parent2_20_0_ from Child children0_ where children0_.parent_id=?
Hibernate: delete from Child where id=?
Hibernate: delete from Child where id=?
Hibernate: delete from Child where id=?
Hibernate: delete from Child where id=?
Hibernate: delete from Parent where id=?


Why select queries are needed and why 4
Code:
delete from Child where id=?
instead of 1
Code:
delete from Child where parent_id=?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2008 10:35 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
I wrote an answer for that, it's here

http://hibernar.org/articulos_en/less_deletes.php

_________________
Gonzalo Díaz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.