JDK 11 and Payara 5 migration: ClassCastException on proxies when using JPA

166 views
Skip to first unread message

Ryan de Laplante

unread,
Mar 5, 2020, 2:24:23 PM3/5/20
to Payara Forum
I am migrating a Java EE 7 web app from Oracle JDK 8 & Payara Server 4 to Open JDK 11 & Payara 5.194.   The app has been around for a while and was built using Spring for bean creation, but is otherwise Java EE.  It uses JSF, JPA, JAX-WS, JAX-RS, JAX-B, etc.

After many changes to my Maven pom.xml I've been able to get it to build and run on Payara 5.194 with JDK 11.  What's strange is certain JPA DAOs consistently cause stack dumps while others are working without issue.   Below are a a couple of examples:

Error while executing named query 'RoomType.findBySiteCodeRoomTypeAndWingCode' : java.lang.ClassCastException: class com.sun.proxy.$Proxy505 cannot be cast to class javax.persistence.Query (com.sun.proxy.$Proxy505 is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @6ae66a2c; javax.persistence.Query is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @2cb6f6c1)
    at com.sun.proxy.$Proxy813.createNamedQuery(Unknown Source)
    at com.ijws.webcico.dao.impl.GenericDaoJpaImpl.findByNamedQuery(GenericDaoJpaImpl.java:162)
    at com.ijws.webcico.dao.impl.GenericDaoJpaImpl.findObjectInstanceByNamedQuery(GenericDaoJpaImpl.java:347)
    at com.ijws.webcico.dao.impl.GenericDaoJpaImpl.findInstanceByNamedQuery(GenericDaoJpaImpl.java:413)
    at com.ijws.webcico.dao.impl.RoomTypeDaoJpaImpl.getRoomType(RoomTypeDaoJpaImpl.java:55)
    at com.ijws.webcico.service.imagecache.roomtype.RoomTypeImageLegacyCache.getStoreImageMetadata(RoomTypeImageLegacyCache.java:103)
    at com.ijws.webcico.service.imagecache.AbstractMultiImageCache.getMetadata(AbstractMultiImageCache.java:44)
    at com.ijws.webcico.service.imagecache.roomtype.RoomTypeImageLegacyCache.listImages(RoomTypeImageLegacyCache.java:65)
    at com.ijws.webcico.service.imagecache.roomtype.RoomTypeImageCompositeCache.listImages(RoomTypeImageCompositeCache.java:47)
    at com.ijws.webcico.web.ui.features.roomselection.UIAlternateRoomTypesController.getImages(UIAlternateRoomTypesController.java:302)


com.ijws.webcico.dao.exception.DAOException: Error while executing named query 'Country.findAll' : java.lang.ClassCastException: class com.sun.proxy.$Proxy512 cannot be cast to class javax.persistence.Query (com.sun.proxy.$Proxy512 is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @7caca14; javax.persistence.Query is in unnamed module of loader org.apache.felix.framework.BundleWiringImpl$BundleClassLoader @57446d64)
    at com.sun.proxy.$Proxy550.createNamedQuery(Unknown Source)
    at com.ijws.webcico.dao.impl.GenericDaoJpaImpl.findByNamedQuery(GenericDaoJpaImpl.java:162)
    at com.ijws.webcico.dao.impl.GenericDaoJpaImpl.findByNamedQuery(GenericDaoJpaImpl.java:205)
    at com.ijws.webcico.dao.impl.CountryDaoJpaImpl.findAll(CountryDaoJpaImpl.java:52)
    at com.ijws.webcico.web.ui.features.countrystate.CountryStateController.getCountrySelectItems(CountryStateController.java:67)


The line that is causing trouble is:

query = entityManager.createNamedQuery(queryName);

Query is javax.persistence.Query and entityManager is javax.persistence.EntityManager.   This all worked before on JDK 8 and Payara 4.   I have spent a lot of time trying to resolve this issue.. so any insight would be greatly appreciated.


Thanks,
Ryan

Ryan de Laplante

unread,
Mar 5, 2020, 3:41:55 PM3/5/20
to Payara Forum
I found something that seems to have resolved the issue.   I mentioned that the app uses Spring for bean creation.  I noticed that the DAOs that work have a @Transactional(propagation=Propagation.REQUIRES_NEW) annotation while the DAOs that don't work do not have that annotation.  I tried adding the annotation to the beans that don't work, and now they work.  @Transactional is a Spring annotation.   I'll have to review whether or not it is correct to be executing these queries in their own transactions, but that is a separate issue.

I find it odd that this is a Spring issue because the stack trace appears to indicate the proxies are created by the Felix OSGI container's org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.  Payara is built using Felix, so I thought it might be a Payara issue.
Reply all
Reply to author
Forward
0 new messages