-->
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: DML-style update problem
PostPosted: Fri Oct 16, 2009 7:28 pm 
Newbie

Joined: Tue Nov 27, 2007 12:16 am
Posts: 4
Hi!

At parent/children pattern, parent know children, but child don't know parent. I want to update a parent's children. I wrote below DML-style update statement:

update children c set c.name='test' where c.id in (select c.id from parent p join p.children c where p.name='parent');

It was translated as below mysql statement:

update children set name='test' where id in (select c.id from parent p inner join children c on p.id=c.parentid where p.name='parent');

But exception throwed when running. It is:

You can't specify target table 'children' for update in FROM clause.

I must do it using DML-style update because performence reason. How can I do?

Thanks very much!


Top
 Profile  
 
 Post subject: Re: DML-style update problem
PostPosted: Mon Oct 19, 2009 5:49 am 
Newbie

Joined: Tue Nov 27, 2007 12:16 am
Posts: 4
OK. It isn't solved now and will not be solved by hibernate or mysql. Because hibernate's author think that is a bug of mysql and must solved by mysql. Other wise, mysql think it isn't a bug. Because they supply a more better way. That is:

update children c inner join (select c.id from parent p inner join children c on p.id=c.parentid where p.name='parent') a on c.id = a.id set name='test';

Of course, it is a good way to update multitable. But it isn't specified in standerer SQL.

I will use PostgreSQL to replace MySQL.

Thanks All.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.