Howto implement SQL EXIST subquery with EntityConditions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Howto implement SQL EXIST subquery with EntityConditions

Rene Scheibe
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

At the moment we remove some entities using a hand-crafted SQL statement
which is quite ugly. Unfortunately we don't know any other solution.

Here is the code snippet so far:


String sql =
  "EXISTS (SELECT p.product_id"
+ "          FROM prodcut p"
+ "         WHERE p.product_id = product_category_member.product_id"
+ "           AND p.primary_product_category_id <>
product_category_member.product_category_id"
+ "           AND p.facility_id = '" + facilityId + "'"
+ ")";

EntityCondition condition = EntityCondition.makeConditionWhere(sql);
delegator.removeByCondition("ProductCategoryMember", condition);


How is it possible to refactor this using EntityConditions?

Regards,
René
- --
René Scheibe * [hidden email] * +49-176-62192936
TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterföhring
Geschäftsführer: Henrik Klagges, Gerhard Müller, Christoph Stock
Sitz: Unterföhring * Amtsgericht München * HRB 135082
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxNqiUACgkQUXs9EHvIuCrXYQCfWCAz2+FyL5/pT1xxySimT2og
nOYAnjRh4990AYLkqv+S2B2SzGJBzWaM
=XT8J
-----END PGP SIGNATURE-----