У меня было приложение, которое отлично работало на jdk 8 и Liberty 22.0.0.10. Я обновляю свое приложение до jdk 21 на Liberty 24.0.0.9 и изменяю pom.xml и некоторые функции на сервере. Приложение запускается, конечные точки REST и очередь jms работают, но при вызове базы данных она получает нулевой указатель, поскольку менеджер объектов em не внедряется (в jdk8 он внедряется правильно и не равен нулю). Выдает эту ошибку:
nliberty.opentracing.internal.OpentracingJaxRsEMCallbackImpl W CWMOT0009W: The OpenTracing exception mapper detected and is handling an unhandled exception from the JAX-RS application.
java.lang.NullPointerException: Cannot invoke "javax.persistence.EntityManager.find(java.lang.Class, Object)" because "this.em" is null
Я использую библиотеку jpa-2.2, и отсюда кажется, что jdk 21 поддерживается. Это наиболее важная часть моего pom (я обновил некоторую библиотеку из версии jdk8):
javax.enterprise
cdi-api
2.0
javax.validation
validation-api
2.0.1.Final
javax
javaee-api
8.0.1
provided
commons-io
commons-io
2.7
org.eclipse.persistence
org.eclipse.persistence.extension
4.0.4
compile
org.glassfish.jersey.media
jersey-media-multipart
2.22.2
provided
javax.ws.rs
javax.ws.rs-api
io.openliberty.features
microProfile-4.0
24.0.0.9
esa
io.openliberty.features
com.ibm.websphere.appserver.javax.jsf-2.2
io.openliberty.features
jpa-2.2
24.0.0.9
esa
io.openliberty.features
beanValidation-2.0
24.0.0.9
esa
io.openliberty.features
mpContextPropagation-1.0
24.0.0.9
esa
${project.artifactId}
org.bsc.maven
maven-processor-plugin
3.3.3
true
--add-modules=javax.annotation
process
process
generate-sources
org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
${build.java.generated}
-Aeclipselink.persistencexml=${project.basedir}/src/local/resources/META-INF/persistence.xml
org.eclipse.persistence
org.eclipse.persistence.jpa.modelgen.processor
2.7.1
org.codehaus.mojo
build-helper-maven-plugin
3.0.0
add-source
process-sources
add-source
${build.java.generated}
Это мои функции на сервере Freedom (я обновил некоторые библиотеки из версии jdk8):
localConnector-1.0
appSecurity-3.0
microProfile-3.3
jpa-2.2
beanValidation-2.0
mpContextPropagation-1.0
jndi-1.0
cdi-2.0
passwordUtilities-1.0
transportSecurity-1.0
ssl-1.0
ejbLite-3.2
concurrent-1.0
ejbPersistentTimer-3.2
Я пытался использовать jakarta вместо javax, но безуспешно (это также сломало мою очередь jms), есть идеи, как исправить этот нулевой указатель?
Изменить:
@Джаред: у меня уже был javax.annotation:javax.annotation-api:1.3, просто исключил его из pom, чтобы он не выглядел слишком длинным.
Это настоящая ошибка:
[24/09/24, 16:12:22:804 CEST] 00000051 com.ibm.ws.jpa.management.JPAApplInfo E CWWJP0029E: The server cannot find the primary persistence unit in the ws-asd-forniture.war module and the ws-asd-forniture application.
[24/09/24, 16:12:22:805 CEST] 00000051 com.ibm.wsspi.injectionengine.InjectionBinding E CWNEN0035E: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved.
[24/09/24, 16:12:22:862 CEST] 00000051 com.ibm.ws.logging.internal.impl.IncidentImpl I FFDC1015I: An FFDC Incident has been created: "com.ibm.wsspi.injectionengine.InjectionException: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved. com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl 201" at ffdc_24.09.24_16.12.22.0.log
[24/09/24, 16:12:22:862 CEST] 00000051 bm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl E CWOWB1000E: A CDI error has occurred: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved.
[24/09/24, 16:12:22:885 CEST] 00000051 com.ibm.ws.logging.internal.impl.IncidentImpl I FFDC1015I: An FFDC Incident has been created: "com.ibm.wsspi.injectionengine.InjectionException: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved. com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl.inject 248" at ffdc_24.09.24_16.12.22.1.log
[24/09/24, 16:12:22:917 CEST] 00000051 com.ibm.ws.logging.internal.impl.IncidentImpl I FFDC1015I: An FFDC Incident has been created: "java.security.PrivilegedActionException: com.ibm.wsspi.injectionengine.InjectionException: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved. com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl 118" at ffdc_24.09.24_16.12.22.2.log
[24/09/24, 16:12:22:917 CEST] 00000051 bm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl E CWOWB1000E: A CDI error has occurred: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved.
[24/09/24, 16:12:23:033 CEST] 00000051 com.ibm.ws.jpa.management.JPAApplInfo E CWWJP0029E: The server cannot find the primary persistence unit in the ws-asd-forniture.war module and the ws-asd-forniture application.
[24/09/24, 16:12:23:034 CEST] 00000051 com.ibm.wsspi.injectionengine.InjectionBinding E CWNEN0035E: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.dao.GenericDao/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved.
[24/09/24, 16:12:23:072 CEST] 00000051 com.ibm.ws.logging.internal.impl.IncidentImpl I FFDC1015I: An FFDC Incident has been created: "com.ibm.wsspi.injectionengine.InjectionException: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.dao.GenericDao/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved. com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl 201" at ffdc_24.09.24_16.12.23.0.log
[24/09/24, 16:12:23:072 CEST] 00000051 bm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl E CWOWB1000E: A CDI error has occurred: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.dao.GenericDao/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved.
[24/09/24, 16:12:23:089 CEST] 00000051 com.ibm.ws.logging.internal.impl.IncidentImpl I FFDC1015I: An FFDC Incident has been created: "com.ibm.wsspi.injectionengine.InjectionException: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.dao.GenericDao/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved. com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl.inject 248" at ffdc_24.09.24_16.12.23.1.log
[24/09/24, 16:12:23:123 CEST] 00000051 com.ibm.ws.logging.internal.impl.IncidentImpl I FFDC1015I: An FFDC Incident has been created: "java.security.PrivilegedActionException: com.ibm.wsspi.injectionengine.InjectionException: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.dao.GenericDao/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved. com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl 118" at ffdc_24.09.24_16.12.23.2.log
[24/09/24, 16:12:23:124 CEST] 00000051 bm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl E CWOWB1000E: A CDI error has occurred: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.dao.GenericDao/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved.
[24/09/24, 16:12:23:134 CEST] 00000051 com.ibm.ws.opentracing.OpentracingJaxRsEMCallbackImpl W CWMOT0009W: The OpenTracing exception mapper detected and is handling an unhandled exception from the JAX-RS application.
java.lang.NullPointerException: Cannot invoke "javax.persistence.EntityManager.find(java.lang.Class, Object)" because "this.em" is null
at it.jajei.nuovaasd.terzeparti.ws.dao.GenericDao.getItemById(GenericDao.java:29)
[others errors...]
[24/09/24, 16:12:23:253 CEST] 00000051 com.ibm.ws.jpa.management.JPAApplInfo E CWWJP0029E: The server cannot find the primary persistence unit in the ws-asd-forniture.war module and the ws-asd-forniture application.
[24/09/24, 16:12:23:254 CEST] 00000051 com.ibm.wsspi.injectionengine.InjectionBinding E CWNEN0035E: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved.
[24/09/24, 16:12:23:255 CEST] 00000051 bm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl E CWOWB1000E: A CDI error has occurred: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved.
[24/09/24, 16:12:23:256 CEST] 00000051 bm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl E CWOWB1000E: A CDI error has occurred: The java:comp/env/it.jajei.nuovaasd.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-asd-forniture.war module of the ws-asd-forniture application cannot be resolved.
[this is another part the application, that if it finds out an error, it try to write it in a database row}
[24/09/24, 16:12:23:553 CEST] 00000051 ei.nuovaasd.terzeparti.ws.server.filter.RequestLoggingFilter E Errore durante le operazioni di tracciamento su LOG_CHIAMATA: Cannot invoke "javax.transaction.UserTransaction.begin()" because "this.userTran" is null
Это первый инцидент с ffdc:
Exception = java.security.PrivilegedActionException
Source = com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl
probeid = 118
Stack Dump = java.security.PrivilegedActionException: com.ibm.wsspi.injectionengine.InjectionException: The java:comp/env/it.jajei.nuovaimu.terzeparti.ws.factory.FactoryResources/em reference of type javax.persistence.EntityManager for the null component in the ws-imu-forniture.war module of the ws-imu-forniture application cannot be resolved.
at java.base/java.security.AccessController.doPrivileged(AccessController.java:575)
at com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl.callInject(WebSphereInjectionServicesImpl.java:132)
at com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl.injectJavaEEResources(WebSphereInjectionServicesImpl.java:114)
at com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl.aroundInject(WebSphereInjectionServicesImpl.java:319)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)
at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:71)
at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:117)
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:161)
at org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:694)
at org.jboss.weld.injection.producer.AbstractMemberProducer.getReceiver(AbstractMemberProducer.java:123)
at org.jboss.weld.injection.producer.AbstractMemberProducer.produce(AbstractMemberProducer.java:158)
at org.jboss.weld.bean.AbstractProducerBean.create(AbstractProducerBean.java:180)
at org.jboss.weld.contexts.unbound.DependentContextImpl.get(DependentContextImpl.java:64)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100)
at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:694)
at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:794)
at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
at org.jboss.weld.util.Beans.injectBoundFields(Beans.java:345)
at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:356)
at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:69)
at com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl$3.run(WebSphereInjectionServicesImpl.java:325)
at com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl$3.run(WebSphereInjectionServicesImpl.java:322)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:319)
at com.ibm.ws.cdi.impl.weld.injection.WebSphereInjectionServicesImpl.aroundInject(WebSphereInjectionServicesImpl.java:322)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:46)
[...omitted]
Это часть класса, слово «основной» соответствует моему файлу persistance.xml:
@ApplicationScoped
@Slf4j
public class GenericDao {
@PersistenceContext(unitName = "primary")
private EntityManager em;
@Resource
UserTransaction userTran;
public T getItemById(Class clazz, Object id) {
return em.find(clazz, id);
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -to-jdk-21
EntityManager не внедряется и имеет значение null при обновлении с jdk 8 до jdk 21 на сервере Liberty. ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Когда использовать EntityManager.find() и EntityManager.getReference() с JPA
Anonymous » » в форуме JAVA - 0 Ответы
- 36 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Ошибка дублирующейся записи JPA в EntityManager.remove, а затем в EntityManager.persist
Anonymous » » в форуме JAVA - 0 Ответы
- 23 Просмотры
-
Последнее сообщение Anonymous
-