Hibernate Union alternatives

You could use id in (select id from …) or id in (select id from …) e.g. instead of non-working from Person p where p.name=”Joe” union from Person p join p.children c where c.name=”Joe” you could do from Person p where p.id in (select p1.id from Person p1 where p1.name=”Joe”) or p.id in (select p2.id … Read more

How do I combine complex polygons?

This is a very good question. I implemented the same algorithm on c# some time ago. The Algorithm constructs a common contour of two polygons (i.e. Constructs a union without holes). Here it is. Step 1. Create graph that describes the polygons. Input: first polygon (n points), second polygon (m points). Output: graph. Vertex – … Read more

SQL Performance UNION vs OR

Either the article you read used a bad example, or you misinterpreted their point. select username from users where company = ‘bbc’ or company = ‘itv’; This is equivalent to: select username from users where company IN (‘bbc’, ‘itv’); MySQL can use an index on company for this query just fine. There’s no need to … Read more

How to get matching data from another SQL table for two different columns: Inner Join and/or Union?

(The following applies when every row is SQL DISTINCT, and outside SQL code similarly treats NULL like just another value.) Every base table has a statement template, aka predicate, parameterized by column names, by which we put a row in or leave it out. We can use a (standard predicate logic) shorthand for the predicate … Read more

Intersection and union of ArrayLists in Java

Here’s a plain implementation without using any third-party library. Main advantage over retainAll, removeAll and addAll is that these methods don’t modify the original lists input to the methods. public class Test { public static void main(String… args) throws Exception { List<String> list1 = new ArrayList<String>(Arrays.asList(“A”, “B”, “C”)); List<String> list2 = new ArrayList<String>(Arrays.asList(“B”, “C”, “D”, … Read more