Closed Incanus3 closed 1 month ago
Instead try:
query.where()
.ilike("id", "%1%")
.eq("processed", "true")
.findCount()
Hi @rob-bygrave and thanks for your time.
Instead try:
query.where() .ilike("id", "%1%") .eq("processed", "true") .findCount()
Nope, fails the same way.
So instead of binding string literal "true", bind true [boolean type].
That is, H2 isn't able to transparently cast the varchar type to boolean type.
Hmm. How is it possible that it works when only the bool filter is applied?
A few implementation related questions then, if I may. This code is part of a generic JSON API implementation, so 1) it doesn't know the specific bean class and property at compile time and 2) the filter value is coming from query params so it always comes in as a string and I'll have to coerce it manually. Hence these questions:
(database as DefaultServer).descriptor(beanClass).property(propName).type().name == "boolean"
. Is this the best way, or is there a simpler/more effective one?DatabaseBuilder.build()
and DatabaseFactory.create()
always return DefaultServer
(coming from DatabaseFactory.createInternal() -> DefaultContainer.createServer()
), their return type is declared as Database
descriptor*()
methods are only available on SpiEbeanServer
(which DefaultServer
implements), not on generic Database
I guess I could use
That is internal API, and instead the Database.pluginApi()
... returns the io.ebean.plugin.SpiServer
which has methods to get io.ebean.plugin.BeanType
etc ... and this is the public API that should be used to access the bean properties. BeanDescriptor, DefaultServer - these are internal types that should not really be used by application code.
Is there a reason why this casting is needed to access bean descriptors?
Use the Database.pluginApi() etc ... we shouldn't need any casting.
comes in as a string and I'll have to coerce it
Yes. Some databases with some types will automatically coerce the types at the database query level but generally with number, boolean and date/time types those should be coerced into the correct type to ultimately bind using JDBC with the correct type.
Use the Database.pluginApi() etc ... we shouldn't need any casting.
Nice, tried this and it works like a charm. Thanks a lot.
generally with number, boolean and date/time types those should be coerced into the correct type
Yeah, I have no problem with that, I'm just pretty surprised that it manages to correctly coerce the param type if it's the only param, but fails when there are two.
Anyway, you managed to solve my problem again. Thank you so much for all the work you put into this great project.
it manages to correctly coerce the param type if it's the only param, but fails when there are two.
Huh, I actually missed that point - yes that seems weird !!
Thank you so much for all the work you put into this great project.
Thanks for that, I really appreciate it.
Ok, I think we can close this one now.
Expected behavior
query should work and return query result
Actual behavior
query fails with
SQLException
Steps to reproduce
Further info