Skip to content

JooqExceptionTranslator loses underlying exception message if SQL state code is unknown #761

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

Closed
matt-snider opened this issue Dec 7, 2022 · 3 comments

Comments

@matt-snider
Copy link

Expected Behavior

Queries that fail should always result in an exception with relevant information about what went wrong. This should happen even if the state code is unknown.

I believe this is the same issue reported in spring-boot#25717. As in that case, I believe the change from PR spring-boot#25493 to the if-block in JooqExceptionTranslator#handle would solve the issue.

Actual Behaviour

For some database errors, the underlying error message from the database is discarded and you get an "Unspecified RuntimeException" message.

Steps To Reproduce

I unfortunately do not have a full repro right now, but I'm guessing the one reported at JOOQ#12708 would work:

dslContext.query("SELECT ST_GeomFromGeoJson('{\"type\":\"Point\"}')").execute();

If you need more information I can look into it, but I'm hoping it's obvious that this change is needed given the existing change to Spring Boot.

Environment Information

No response

Example Application

No response

Version

v3.7.4

@matt-snider
Copy link
Author

Ah I think the changes in the referenced PR didn't end up being merged, I believe instead that this is the correct commit

spring-projects/spring-boot@7ef9ca0

@matt-snider
Copy link
Author

matt-snider commented Dec 13, 2022

Okay, while investigating this I attempted to override the JooqExceptionTranslator, which led me to an error about the org.springframework.jdbc.support package not existing.

I changed the spring-jdbc dependency from runtimeOnly to compileOnly and it fixed the issue. So it seems that I didn't have Spring configured correctly and that bean was not being instantiated.

Still, I'm a bit confused about what the proper setup is. The docs now say to specify:

implementation("io.micronaut.sql:micronaut-hibernate-jpa-spring")

But I have the following which looks like it was the way from v3 docs (other than compileOnly and runtimeOnly):

annotationProcessor("io.micronaut.spring:micronaut-spring-annotation")
implementation("io.micronaut.spring:micronaut-spring")
compileOnly("org.springframework:spring-jdbc")

If I use the new recommended method I get an exception about entities missing:

Error instantiating bean of type  [org.hibernate.boot.SessionFactoryBuilder]

Message: Entities not found for JPA configuration: 'default' within packages [...]. Check that you have correctly specified a package containing JPA entities within the "jpa.default.entity-scan.packages" property in your application configuration and that those entities are either compiled with Micronaut or a build time index produced with @Introspected(packages="foo.bar", includedAnnotations=Entity.class) declared on your Application class

This looks to be some configuration that is now required but wasn't previously. I don't see this mentioned in the release notes though. Any advice would be appreciated to get the equivalent of the old behaviour without breaking anything

@matt-snider
Copy link
Author

Okay so I realized I was looking in the wrong section for the current docs. Likely the JDBC section would be more applicable, but that still doesn't get me both the Transaction Manager working with @Transactional and the JooqExceptionTranslator. That's my bad.

I do think this still shows in a way that it's tricky to get transactions set up properly with JOOQ and Micronaut-SQL (see #558). I will comment there and close this. Sorry for the mixup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant