JPA 2.0 / Hibernate - why hibernate issue select count (*) query before delete -


i using spring-data hibernate. have bidirectional mapping follow:

public class student {    ...    @onetomany(fetch = fetchtype.eager, cascade = cascadetype.all, orphanremoval = true,    mappedby="student")    private list<studentlog> logs = newarraylist();      ... }  public class studentlog {    .....     @manytoone(cascade = cascadetype.refresh, optional = false, fetch = fetchtype.lazy)     @joincolumn(name = "student_id" , insertable = true, updatable = false, nullable =false)     private student student;    ..... } 

when delete student using jparepository: repo.delete(s.getid()); can see following queries

hibernate: select count(*) col_0_0_ students student0_ student0_.id=? , 1=1 hibernate: select student0_.id id1_2_2_, student0_.first_name first2_2_2_,  educationh1_.student_id student6_2_4_, educationh1_.id id1_0_4_, educationh1_.id  id1_0_0_, educationh1_.class class2_0_0_, educationh1_.level level3_0_0_, educationh1_.predicted_end_date predicte4_0_0_, educationh1_.start_date start5_0_0_, educationh1_.student_id student6_0_0_, educationh1_.term term7_0_0_, logs2_.student_id student3_2_5_, logs2_.id id1_3_5_, logs2_.id id1_3_1_, logs2_.log log2_3_1_, logs2_.student_id student3_3_1_ students student0_ left outer join education_history educationh1_ on student0_.id=educationh1_.student_id left outer join student_log logs2_ on student0_.id=logs2_.student_id student0_.id=? hibernate: delete student_log id=? hibernate: delete students id=? 

any idea why hibernate issue 2 select queries? not possible issue delete queries without selects?

thanks

jpa exposes remove(…) method on entitymanager takes entity deleted. call delete(…) id first check whether entity id existst (first query). materialize object (second query) hand entitymanager.remove(…) (query 3 , 4).

actually exists(…) check superfluous can check null in second step. i've created , fixed datajpa-363, should see 1 query less in future.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -