-->
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.  [ 10 posts ] 
Author Message
 Post subject: please,hql delete problem
PostPosted: Tue Jul 18, 2006 1:27 pm 
Beginner
Beginner

Joined: Sun May 07, 2006 2:44 pm
Posts: 33
version 3.2

Please , i am desperate!!!!!

I have QueryEvent that has one-to-many relation with BusinessRules
(This is not bi-directional)
The Fk is in the BusinessRules to the QueryEvent

i want to run the following sql:
Code:
   DELETE FROM business_rules
WHERE EXISTS
  (select *
    from QUERY_EVENTS
    where business_rules.QueryEvent_BusinessRule_Hjid = QUERY_EVENTS.Hjid and QUERY_EVENTS.Hjid = 25);


so i write the following Hql:
Code:
"delete from BusinessRule br where exists(from QueryEvent q where q.BusinessRule = br.Hjid and q.Hjid = 26)"


but hibernate generate the following illegal sql:
Code:
delete from BUSINESS_RULES where exists (select queryevent1_.Hjid from QUERY_EVENTS queryevent1_, BUSINESS_RULES businessru2_ where queryevent1_.Hjid=businessru2_.QueryEvent_BusinessRule_Hjid and .=BUSINESS_RULES.Hjid and queryevent1_.Hjid=26)


the problem is :
the section - and
Code:
.=BUSINESS_RULES.Hjid
.
java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=BUSINESS_RULES.Hjid and queryevent1_.Hjid=26)' at line 1

i tried with " exists " but than i got a sql exception that i cant update in a from clause (hibernate write the child again in the exists clause)

please , advice.

please!!!!!!!!
how can i delete a child in hql???? (the best will be if i can delete the child and the parent but i understood that hql dosnt support in cascade , so i get constraits violation)

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 4:32 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
try this:
Code:
delete from BusinessRule br
where
   exists(
      from
         QueryEvent q
         inner join q.BusinessRule qbr
      where
         qbr = br.Hjid
         and
         q.Hjid = 26
   )


Top
 Profile  
 
 Post subject: Your solution dosnt work -
PostPosted: Wed Jul 19, 2006 2:31 am 
Beginner
Beginner

Joined: Sun May 07, 2006 2:44 pm
Posts: 33
It generate the following sql :

Code:
   delete from BUSINESS_RULES where exists (select queryevent1_.Hjid, businessru2_.Hjid from QUERY_EVENTS queryevent1_ inner join BUSINESS_RULES businessru2_ on queryevent1_.Hjid=businessru2_.QueryEvent_BusinessRule_Hjid where Hjid=BUSINESS_RULES.Hjid and queryevent1_.Hjid=27)


as you can see this sql is illegall:
Code:
java.sql.SQLException: Column 'Hjid' in where clause is ambiguous


I write the following hql:
Code:
delete from BusinessRule br where exists(from QueryEvent q where q.Hjid = 27)


And it work.

Thank you.


Top
 Profile  
 
 Post subject: My mistake . my hql delete all the records , so it is not
PostPosted: Wed Jul 19, 2006 3:10 am 
Beginner
Beginner

Joined: Sun May 07, 2006 2:44 pm
Posts: 33
solve the problem.

So, plllllllllllllllllease .
How can i delete child in hql????


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 4:52 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
try this:
Code:
delete from BusinessRule br
where
   exists(
      from
         QueryEvent q
         inner join q.BusinessRule qbr
      where
         qbr = br
         and
         q.Hjid = 28
   )


Top
 Profile  
 
 Post subject: No, Column 'Hjid' in where clause is ambiguous
PostPosted: Wed Jul 19, 2006 6:42 am 
Beginner
Beginner

Joined: Sun May 07, 2006 2:44 pm
Posts: 33
10:40:55,230 DEBUG JDBCExceptionReporter:63 - could not execute update query [delete from BUSINESS_RULES where exists (select queryevent1_.Hjid, businessru2_.Hjid from QUERY_EVENTS queryevent1_ inner join BUSINESS_RULES businessru2_ on queryevent1_.Hjid=businessru2_.QueryEvent_BusinessRule_Hjid where Hjid=Hjid and queryevent1_.Hjid=34)]

java.sql.SQLException: Column 'Hjid' in where clause is ambiguous


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 19, 2006 12:20 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
a last try:
Code:
delete from BusinessRule br
where
   exists(
      from
         QueryEvent q
         inner join q.BusinessRule qbr
      where
         qbr.Hjid = br.Hjid
         and
         q.Hjid = 69
   )


Top
 Profile  
 
 Post subject: Thank,but not working. never mind
PostPosted: Thu Jul 20, 2006 2:35 am 
Beginner
Beginner

Joined: Sun May 07, 2006 2:44 pm
Posts: 33
This the sql generate:
Code:
delete from BUSINESS_RULES where exists (select queryevent1_.Hjid, businessru2_.Hjid from QUERY_EVENTS queryevent1_ inner join BUSINESS_RULES businessru2_ on queryevent1_.Hjid=businessru2_.QueryEvent_BusinessRule_Hjid where businessru2_.Hjid=BUSINESS_RULES.Hjid and queryevent1_.Hjid=34)


This is the exception:SqlException
Code:
You can't specify target table 'BUSINESS_RULES' for update in FROM clause


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 3:47 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
Try with a slightly different form:

Code:
   delete from BusinessRule br
   where br.Hjid in
   (
      select br2.Hjid
      from QueryEvent as qe
      inner join  qe.BusinessRule as br2
      where qe.Hjid = 34
   )


Top
 Profile  
 
 Post subject: Same problem. never mind.
PostPosted: Thu Jul 20, 2006 7:07 am 
Beginner
Beginner

Joined: Sun May 07, 2006 2:44 pm
Posts: 33
Hibernate generate new BusinessRule in the inner sql query.
this is the problem


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