Cannot access added as module jdbc postgres jar - WildFly 10.1
drzeyan Jan 31, 2017 8:06 AMI have postgres jdbc driver configured as module in Wildfly 10.1. What I am trying to do, is to use that driver as dependency in application that will be deployed on the server. In application, I mark this dependency as provided (in Maven's pom.xml. I do the same with jboss-logging or java-ee dependency) but it seems to be not working.
Current configuration:
Wildfly postgres module is added at wildfly-10.1.0.Final\modules\org\postgresql\main
where there is: postgresql-9.4-1206-jdbc4.jar
and module.xml
with following content:
<module xmlns="urn:jboss:module:1.1" name="org.postgresql"> <resources> <resource-root path="postgresql-9.4-1206-jdbc4.jar"/> </resources> <dependencies> <module name="javax.api"/> <module name="javax.transaction.api"/> </dependencies> </module>
Module is used to define datasource. To this point, everything is working well - with hibernate help tables are happily mapped to entities. Except one thing:
I started to map postgres-jsonb columns with use of javax.persistence.AttributeConverter
and following happens:
Scenario 1
When I mark postgresql-9.4-1206-jdbc4.jar
as a provided
(in pom.xml - deployed application), I get following error trying to convert anything:
Caused by: java.lang.ClassNotFoundException: org.postgresql.util.PGobject from [Module "deployment.project-1.0.1.ear.project.data-1.0.1-SNAPSHOT.jar:main" from Service Module Loader] at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198) at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363) at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351) at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93) ... 269 more
Which means that postgres jar somehow can not be accessed. I expected that this will work the same as java-ee or jboss-logging dependencies which I mark as provided, but apparently it's not.
Scenario 2
When I use postgresql-9.4-1206-jdbc4.jar
with default scope, there is following error:
Caused by: java.lang.ClassCastException: org.postgresql.util.PGobject cannot be cast to org.postgresql.util.PGobject at com.project.entity.util.converters.JSONBTypeConverter.convertToEntityAttribute(JSONBTypeConverter.java:33) at com.project.entity.util.converters.JSONBTypeConverter.convertToEntityAttribute(JSONBTypeConverter.java:1) at org.hibernate.type.descriptor.converter.AttributeConverterSqlTypeDescriptorAdapter$2.doConversion(AttributeConverterSqlTypeDescriptorAdapter.java:140) ... 266 more
Which means: class loader loads the same jar two times, and can not cast objects to itself.
Question: Why provided
scope of the dependency does not work for manually added (to wildfly) postgres driver?