开发者

How to make a like query to @ElementCollection of type map?

开发者 https://www.devze.com 2023-03-28 09:10 出处:网络
I have a class like this: class MyEntity { @ElementCollection Map<String, String> properties; } I\'d like to find out which MyEntity entities have a property value that matches like query usi

I have a class like this:

class MyEntity {
    @ElementCollection
    Map<String, String> properties;
}

I'd like to find out which MyEntity entities have a property value that matches like query using the criteria API. By this I mean I'd like to make a like query开发者_StackOverflow中文版 on the values of the map entries.

For example if one of my MyEntity classes has a property named "email" and the value is "example@mail.com", how do I make a query that finds the entity with a query parameter "example%" using criteria API?


Okay, I found a solution. There is a joinMap(String) method in Path API which can be used in this case:

builder.like(
    root.<MyEntity, String, String>joinMap("properties").value(), "example%");

That piece of code will create a like predicate against the values of the properties map. This would probably been easier to find out if I had generated the MetaModel of the MyEntity...

0

精彩评论

暂无评论...
验证码 换一张
取 消