user2444474
user2444474

Reputation: 573

How to do addAll from multiple sql result in hibernate?

I'm running sql seperately, because hibernate doesn't support "union". So how to do addAll from those results.

public List<Product> findlist(String pid) {
     List <Product> result1 ; 
     List <Product> result2; 
     Object[] obj = {pid}; 
      result1.add(findAllByQuery(PRODUCT_DIVISION1,obj));
      result1.add(findAllByQuery(PRODUCT_DIVISION2,obj));
      return result1.addAll(result1);
  }

PRODUCT_DIVISION1 = "query";
PRODUCT_DIVISION2 = "query";

Please advise.

Upvotes: 1

Views: 780

Answers (1)

gerrytan
gerrytan

Reputation: 41133

return result1.addAll(result1); doesn't make sense to me, it's adding the content of itself. Also the 'add' method supposed to be used to add one element only. You list is also uninitialized.

What you're trying to achieve sounds straight forward, you just need to query each collection and combine it

List <Product> result = findAllByQuery(PRODUCT_DIVISION1,obj);
result.addAll(findAllByQuery(PRODUCT_DIVISION2,obj)
return result;

Upvotes: 1

Related Questions