Function call on where #950
Unanswered
MateusSilvaFreitas
asked this question in
Q&A
Replies: 1 comment
-
Hello, @Dao
public interface HotelDao {
@Sql("""
select * from hotel h
where levenshtein(h.city, /* city */'New York') <= ((length(h.city) * 20) / 100);
""")
@Select
List<Hotel> findHotelByCity(String city);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am trying to create a query using entityql.
In this query, I need to filter the results calling a function(I am doing this to don't perform a for-each for every element of response).
Here is the query that I am trying to execute:
select * from hotel h where levenshtein(h.city, 'New York') <= ((length(h.city) * 20) / 100);
This "levenshtein" function, is a function on my database that will return the difference of two words, and this difference must be lower than twenty percent of the city name string.
I try to create a default method on my interface, but when I try to use, one of the parameters of where, must be a PROPERTY.
Here is the code of default method in interface
default int levenshtein(@NonNull String string1, @NonNull String string2){
Config config = Config.get(this);
SelectBuilder builder = SelectBuilder.newInstance(config);
builder.sql(String.format("select levenshtein(%s, %s)", string1.toUpperCase(), string2.toUpperCase()));
return builder.getScalarSingleResult(int.class);
}
and in the implementation of this interface, this is the method:
public List<Hotel> findHotelByCity(String city) {
Hotel_ hotel = new Hotel_();
Optional<Hotel> hotelResult = entityql.from(hotel)
.where(h -> h.le(levenshtein(hotel.city, city), (city.length() * 20) / 100 ))
.fetchOptional();
return null;
}
So, i have this error on the code:

So, how i execute this stored function in the where of this method?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions