Classloading from Hiberate in a datasource driver on WildFly 27

448 views
Skip to first unread message

Emond Papegaaij

unread,
Nov 8, 2022, 11:28:13 AM11/8/22
to WildFly
Hi all,

We are in the process of migrating our applications from WildFly 26.1.2 to 27.0.0.Alpha5 (including the JEE10 migration) and are running into an issue with the way we configure our datasources. We target alpha5 at the moment because we are having issues with the new jandex in beta1, but I don't think that will affect this issue. On WF 26 we create a module for the postgres driver with the very simple definition:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.postgresql">
        <resources>
                <resource-root path="postgresql.jar"/>
        </resources>
        <dependencies>
                <module name="javax.api"/>
                <module name="javax.transaction.api"/>
        </dependencies>
</module>

This module is then loaded as a driver in the datasources subsystem:

<drivers>
    <driver name="postgresql" module="org.postgresql">
        <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
    </driver>
</drivers>

We've had no trouble at all with this setup for years, but with WildFly 27 we are getting classloading issues from hibernate (stacktrace below). It seems hibernate cannot access the classes from the postgresql driver directly. Do we need to open up the driver module to hibernate somehow, or maybe explicitly add a dependency somewhere? If yes, how?

Caused by: java.lang.ClassNotFoundException: org.postgresql.util.PGobject from [Module "org.hibernate" version 6.0.2.Final from local module loader @6eeade6c (finder: local module finder @4a891c97 (roots: /opt/jboss/wildfly/modules,/opt/jboss/wildfly/modules/system/layers/base))]
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:200)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Unknown Source)
        at org.hi...@6.0.2.Final//org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:163)
        at org.hi...@6.0.2.Final//org.hibernate.dialect.PostgreSQLPGObjectJdbcType.<clinit>(PostgreSQLPGObjectJdbcType.java:41)
        ... 17 more

Best regards,
Emond Papegaaij

Scott Marlow

unread,
Nov 8, 2022, 12:19:07 PM11/8/22
to Emond Papegaaij, WildFly

That is fixed already in later Hibernate ORM releases.  You could workaround the failure by updating the "org.hibernate" module to depend on the "org.postgresql" module to avoid ClassNotFoundException deployment failure.

--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/9c93d90a-1c2e-46de-a171-d06f4ece842bn%40googlegroups.com.

Emond Papegaaij

unread,
Nov 8, 2022, 1:48:57 PM11/8/22
to WildFly
On Tuesday, 8 November 2022 at 18:19:07 UTC+1 sma...@redhat.com wrote:

That is fixed already in later Hibernate ORM releases.  You could workaround the failure by updating the "org.hibernate" module to depend on the "org.postgresql" module to avoid ClassNotFoundException deployment failure.

That's good to hear. I suspect this was HHH-15438, fixed in Hibernate ORM 6.1.3 and WildFly 27.0.0.Beta1? I thought of patching the org.hibernate module, but I'd rather not change modules provided by WildFly to depend on application-specific drivers. The fix for HHH-15438 only prevents the deployment failure, but the types are still not usable. I don't know if these types were available in older versions of Hibernate ORM, but the current solution seems sub-optimal. Is this going to be addressed in a future version of WildFly, or do we need to change something in the way we setup our datasource?

Best regards,
Emond

Scott Marlow

unread,
Nov 8, 2022, 2:47:21 PM11/8/22
to Emond Papegaaij, WildFly

Actually, I think you already have the fix for https://issues.redhat.com/browse/WFLY-16752 "Make it possible for Hibernate ORM to be able to access org.postgresql.jdbc and com.oracle.ojdbc JDBC driver classes" which expects the postgres module name to be "org.postgresql.jdbc" (see https://github.com/wildfly/wildfly/commit/5a781beb784f387dc17f478d762982a857eeed90).  So try updating the postgres driver module name.

Scott


Best regards,
Emond
--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.

Emond Papegaaij

unread,
Nov 8, 2022, 4:03:29 PM11/8/22
to WildFly
On Tuesday, 8 November 2022 at 20:47:21 UTC+1 sma...@redhat.com wrote:
Actually, I think you already have the fix for https://issues.redhat.com/browse/WFLY-16752 "Make it possible for Hibernate ORM to be able to access org.postgresql.jdbc and com.oracle.ojdbc JDBC driver classes" which expects the postgres module name to be "org.postgresql.jdbc" (see https://github.com/wildfly/wildfly/commit/5a781beb784f387dc17f478d762982a857eeed90).  So try updating the postgres driver module name.

Yes, I can confirm that changing the module name fixes the error. This does however seem a bit fragile. It will work for our case, but this will also expose the postgresql classes to Hibernate ORM when using a different database. It would be nice if Hibernate ORM could somehow get access to the module that is defined with the driver of the datasource rather than relying on the names of driver modules and exposing all.

Best regards,
Emond

Scott Marlow

unread,
Nov 8, 2022, 5:05:35 PM11/8/22
to Emond Papegaaij, WildFly

That would be a nice enhancement!

Scott


Best regards,
Emond
--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages