0

I have been trying for a while to convert a list of longs into a expression of longs, the purpose of the exercise is to use it in the Criteria Builder "IN" clause so it really has to be an Expression

List<Long> numbers = new ArrayList<>();
numbers.add(1L);
numbers.add(2L);
javax.persistence.criteria.Expression<Long> expressionOfNumbers = (Expression<Long>) numbers;

//query code...
query.where(cb.in(expressionOfNumbers));

All help is appreciated. Thank You.

pedrofranco6
  • 15
  • 1
  • 6
  • What expression are you talking about? `com.sun.javafx.fxml.expression.Expression`? – Sweeper May 21 '18 at 09:15
  • How would you create a single `Expression`? – ernest_k May 21 '18 at 09:16
  • 1
    @Sweeper I think it would be `javax.persistence.criteria.Expression`. – MC Emperor May 21 '18 at 09:17
  • Judging by the fact that author mentioned criteria api this would be org.hibernate.criterion.Expression. Anyway, there is no simple built in way to do that. Just create a new Expression with constructor, and use a for loop to add the values. You could also use stream api and implement your own Collector. Worth considering if you do that a lot, otherwise more of a mind-training excercise – Jan Ossowski May 21 '18 at 09:17
  • Oh yeah, it can also be what @MCEmperor said, I guess we need to wait for the author to make up his mind :D – Jan Ossowski May 21 '18 at 09:18
  • Just clarified the question the Expression type is "javax.persistence.criteria.Expression". – pedrofranco6 May 21 '18 at 09:20

0 Answers0