question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Postgres] [OID] [Quarkus] [rider-cdi] java.lang.ClassCastException: class io.agroal.pool.wrapper.ConnectionWrapper cannot be cast to class org.postgresql.PGConnection

See original GitHub issue

Using rider-cdi (1.18.0) in Quarkus, trying to validate test results via @ExpectedDataSet for a table containing an oid-typed column I get above exception

java.lang.ClassCastException: class io.agroal.pool.wrapper.ConnectionWrapper cannot be cast to class org.postgresql.PGConnection

Stacktrace

   at org.dbunit.ext.postgresql.PostgreSQLOidDataType.getSqlValue(PostgreSQLOidDataType.java:42)
at org.dbunit.database.ForwardOnlyResultSetTable.getValue(ForwardOnlyResultSetTable.java:104)
at org.dbunit.dataset.DefaultTable.addTableRows(DefaultTable.java:139)
at org.dbunit.database.CachedResultSetTable.<init>(CachedResultSetTable.java:69)
at org.dbunit.database.CachedResultSetTableFactory.createTable(CachedResultSetTableFactory.java:61)
at org.dbunit.database.DatabaseDataSet.getTable(DatabaseDataSet.java:338)
at com.github.database.rider.core.dataset.DataSetExecutorImpl.compareCurrentDataSetWith(DataSetExecutorImpl.java:1004)
at com.github.database.rider.core.dataset.DataSetExecutorImpl.compareCurrentDataSetWith(DataSetExecutorImpl.java:1062)
at com.github.database.rider.core.dataset.DataSetExecutorImpl.compareCurrentDataSetWith(DataSetExecutorImpl.java:1057)
at com.github.database.rider.cdi.DataSetProcessor.compareCurrentDataSetWith(DataSetProcessor.java:155)

Reason

PostgreSQLOidDataType gets a Agroal-wrapped connection and cast fails

Suggestion

Could you unwrap the connection prior to passing it to DBUnit, maybe in https://github.com/database-rider/database-rider/blob/06f738fdfe6ab7f2d5a6711c1115c5e5672025f0/rider-core/src/main/java/com/github/database/rider/core/connection/RiderDataSource.java#L84?

Also

Possibly related to #111

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rmpestanocommented, Jan 9, 2021

Hi, thanks for checking!

1.21.1 should be at maven central in next hours.

Thank you again!

0reactions
coiouhkccommented, Jan 9, 2021

Hi @rmpestano, thanks for the quick fix - i tried it in both reproducer and real projects and both now work OK with regards to the issue. When do you plan to release the fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Re: Cast java.sql.Connection to PGConnection - PostgreSQL
Caused by: java.lang.ClassCastException: >> org.apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper >> cannot be cast to ...
Read more >
Reactive SQL Clients - Quarkus
Currently, the following database servers are supported: IBM Db2. PostgreSQL. MariaDB/MySQL. Microsoft SQL Server. Oracle ...
Read more >
Cast java.sql.Connection to PGConnection - Stack Overflow
if (dataSource.getConnection().isWrapperFor(PGConnection.class)) { PGConnection pgConnection = dataSource.
Read more >
Quarkus build fails because it can't connect to the DB
at org.postgresql.Driver.connect(Driver.java:264). at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:204).
Read more >
Thread: Cast java.sql.Connection to PGConnection
lang.ClassCastException: org.apache.tomcat.dbcp.dbcp2.PoolingDataSource$PoolGuardConnectionWrapper cannot be cast to org.postgresql.PGConnection ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found