I am using Hibernate with JpaRepositories.
The relevant part of the Entity class is:
@Entity
public class Person {
//.. id and other attributes
@Column(name = "function")
@ElementCollection
private Set<String> functions;
// .. getter setter
}
I needed to change my Entity class from having only one function to be able to handle multiple functions. There is a search function in one of my DAOs that can compare all existing functions with a string, in hope to find already defined functions.
the original JPA Query was:
select DISTINCT(p.function) from Person p where UPPER(p.function) like UPPER(:term) order by p.function
how can I archive the same result with the new @ElementCollection?
You need to join the collection to Person and then select. Try this query:
select DISTINCT(f) from Person p join p.functions f where UPPER(f) like UPPER(:term) order by f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With