# In pure JPA, Can an @ElementCollection with @CollectionTable contain non-entities?

**URL:** https://discourse.hibernate.org/t/in-pure-jpa-can-an-elementcollection-with-collectiontable-contain-non-entities/3064
**Category:** Hibernate ORM
**Created:** [August 6, 2019, 10:51pm UTC](https://discourse.hibernate.org/t/in-pure-jpa-can-an-elementcollection-with-collectiontable-contain-non-entities/3064 "2019-08-06T22:51:43Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![systemasephiro](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/systemasephiro/32/95_2.png) [@systemasephiro](https://discourse.hibernate.org/u/systemasephiro)
#### Post date: [August 6, 2019, 10:51pm UTC](https://discourse.hibernate.org/t/in-pure-jpa-can-an-elementcollection-with-collectiontable-contain-non-entities/3064/1 "2019-08-06T22:51:43Z")

</div>

In my entity, I have an effectively one-to-many reference to another table. This other table, which only has two fields just contains a list of integers for each entry present in my first entity table, with uniqueness on each combination. In the first entity, this is the declaration for my @ElementCollection representing that other table:

`@CollectionTable(name = "other_table", joinColumns = @JoinColumn(name = "my_id")) @ElementCollection private Set<Integer> mynumbers = new HashSet<>();`

What I am wondering is, can I refer to this structure from JPQL or criteria query without having to make a separate entity that represents that other table? Currently it seems like this isn’t possible, as I receive “column not found” type error when querying “:param MEMBER OF mynumbers” in JPQL or criteria query, so it’s assuming that I actually have a column by that name. I am able to query the other table if I create an entity for it, is that the only way? I’m wondering if this is the case or if there’s something I am missing. Thanks

---

<div class="post-metadata">

### Author: ![systemasephiro](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/systemasephiro/32/95_2.png) [@systemasephiro](https://discourse.hibernate.org/u/systemasephiro)
#### Post date: [September 6, 2019, 11:33pm UTC](https://discourse.hibernate.org/t/in-pure-jpa-can-an-elementcollection-with-collectiontable-contain-non-entities/3064/2 "2019-09-06T23:33:32Z")

</div>

Found out how to do this with ParameterExpression, as described here. No need to use MEMBER OF

> **[Hibernate Tips: How to use @ElementCollection entries in a query](https://thoughts-on-java.org/hibernate-tips-query-elementcollection/)**
>
> I don't recommend using @ElementCollection but if you do, here is how you can reference its element in a JPQL and Criteria query.
