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

一世执手 提交于 2019-12-12 02:12:23

问题


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 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?


回答1:


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...



来源:https://stackoverflow.com/questions/7066122/how-to-make-a-like-query-to-elementcollection-of-type-map

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!