-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversion failure when handling ARRAY types with HSQLDB #6452
Comments
Also of note: the following also fails. r.get(field(name("roles"), String[].class)) Produces the following trace:
|
Next idea: get it back as an Nope:
OK, finally the nuclear option: get it back as Sure, that works... but at that point we've lost any vague semblance of type safety, let alone a pleasant API. |
Indeed, this conversion is currently not supported. Interesting. We do support the inverse conversion (from The workaround is simple: Use an explicit Field<Integer> id = r.get(name("id"), Integer.class);
Field<String[]> roles = field(name("roles"), String[].class);
return this.dsl
.select(id, roles, ...)
.from(TABLE)
.where(id).in(ids))
.fetchMap(id,
r -> {
final Collection<GrantedAuthority> rolesCollection =
Stream.of(r.get(roles))
.map(SimpleGrantedAuthority :: new)
.collect(Collectors.toList());
return new User(r.get(roles), ...,
rolesCollection );
}); |
I'm closing this as a duplicate of #6454 |
Great, thanks! I'll give that a shot. One aside though: why does the code in the initial report work under PostgreSQL but not other DBs? |
If I remember correctly, the PostgreSQL JDBC driver deserialises arrays as Java |
Ah. That makes sense. I'll use the above workaround (which works fine, BTW) until #6454 lands. Thanks! |
I wouldn't see it as a workaround. If you know the exact type you want to project, it's always better to pass that to the jOOQ |
Fair enough. I think we're getting into software engineering philosophy here, so we'll have to agree to disagree on that particular point. 😉 Bottom line is, the above approach works fine and solves the issue I originally encountered. Thanks as always! |
Well, we can disagree on |
I was referring to the The jOOQ bit I'm all ears for. You are kinda the world expert. ;) Is there any performance advantage to specifying the fields from jOOQ's perspective (leaving the DB's performance characteristics out of it), or is it just typing? |
There's the slight advantage of not having to instanciate any intermediate types (like said Of course, if you're selecting all columns, say 500 of them, and then reject most of them in the client, that also incurs significant overhead in the client's CPU and memory consumption. This is not really just part of the DB's performance characteristics... |
Oh yeah, I should have clarified I was talking about the case where you're actually using all of the stuff that you bring back with a I'll keep the GC pressure in mind. |
I see. No, then there's no significant advantage to specify fields in the |
In fact, while #6454 is a nice to have addition, the real problem here is simply that jOOQ doesn't recognise the So, it would make perfect sense to implement this behaviour also for HSQLDB: |
Huh? How would |
Sorry for the confusion. I wrote a test case with integer arrays, in case of which |
Gotcha. Thanks for tackling this, BTW. jOOQ continues to impress me in how comprehensive it is re: database support. |
Thanks for your nice words. Yeah, jOOQ has seen 1-2 things in the last 9 years :) |
Well you'll continue to have a steady stream of users with cross-DB use cases like mine. And some of us users will be stubborn/dumb enough to use the API without codegen. So plenty of good test coverage there... 😉 |
Sure, that's where the interesting edge cases show up :) |
Description
I am unable to get a table with an ARRAY column to work properly with jOOQ's DSL API (no code-gen) when using a non-Postgres DB (in this case HSQLDB)
Environment
Java 8, HSQLDB 2.3.4, jOOQ 3.9.3 (repro'd back to 3.9.0)
Steps to reproduce
Expected outcome
Query completes successfully (as it does under PostgreSQL 9.4).
Actual outcome:
An exception is thrown, sample trace as follows:
Workaround
Use raw
java.sql.Array
as the field type, go from there.The text was updated successfully, but these errors were encountered: