0

I have an entity as follows:

public class Foo {

    private List<String> bars;

    @ElementCollection(fetch=FetchType.LAZY)
    @CollectionTable(name="T_BARS", joinColumns=@JoinColumn(name = "ID"))
    @Column(name="BAR")
    public List<String> getBars() {
        return bars;
    }
}

now I' m trying to query all the elements foo that contains bar elements with id 'a', 'b' or 'c' but I do not manage to make it work.

I tried the two following approaches:

select from FOO as f where f.bars in elements
(select b.id from T_BARS as b where b.bar in elements('a','b','c'))

this yields a QuerySyntaxException: T_BARS not mapped

My second approach was the following:

select from FOO as f where elements('a','b','c') in elements(f.bars)

this yields a QuerySyntaxException unexpected token

EDIT: I'm using envers, so joins do not seem possible!?

phury
  • 2,123
  • 2
  • 21
  • 33

1 Answers1

0

It seems as joins are not possible in envers from jobss forum, so I ended up splitting the query. It's not elegant but it does the job and the provided list will never be to big:

select from FOO as f where
('a' in elements(f.bars)
  or 'b' in elements(f.bars)
  or 'c' in elements(f.bars)
  or ...)
...
phury
  • 2,123
  • 2
  • 21
  • 33