重新启动 karaf 所需的捆绑包更新

Posted

技术标签:

【中文标题】重新启动 karaf 所需的捆绑包更新【英文标题】:Bundle update requres to restart karaf 【发布时间】:2015-12-03 17:49:57 【问题描述】:

当使用 Hibernate 的特定包更新时,会发生持久性异常:

java.lang.reflect.UndeclaredThrowableException
        at com.sun.proxy.$Proxy71.persist(Unknown Source)
        at com.aurimas.edi.persistence.service.impl.Hl7StagingAreaServiceImpl.persistHl7Message(Hl7StagingAreaServiceImpl.java:37)[249:com.aurimas.edi.osgi-adapter-bi-sa-db:1.0.0.SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_60]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_60]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_60]
        at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_60]
        at org.apache.aries.proxy.impl.ProxyHandler$1.invoke(ProxyHandler.java:54)
        at org.apache.aries.proxy.impl.ProxyHandler.invoke(ProxyHandler.java:119)
        at com.aurimas.edi.persistence.service.impl.$Hl7StagingAreaServiceImpl1100807931.persistHl7Message(Unknown Source)[249:com.aurimas.edi.osgi-adapter-bi-sa-db:1.0.0.SNAPSHOT]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_60]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_60]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_60]
        at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_60]
        at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:408)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:279)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:252)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:167)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.directvm.DirectVmProcessor.process(DirectVmProcessor.java:55)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.directvm.DirectVmProducer.process(DirectVmProducer.java:55)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:120)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.directvm.DirectVmProcessor.process(DirectVmProcessor.java:55)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.directvm.DirectVmProducer.process(DirectVmProducer.java:55)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:120)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:423)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)[76:org.apache.camel.camel-core:2.14.0]
        at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)[76:org.apache.camel.camel-core:2.14.0]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_60]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)[:1.8.0_60]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)[:1.8.0_60]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)[:1.8.0_60]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_60]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_60]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_60]
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_60]
        at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_60]
        at org.apache.aries.jpa.container.context.transaction.impl.JTAEntityManagerHandler.invoke(JTAEntityManagerHandler.java:185)
        ... 53 more
Caused by: java.lang.reflect.UndeclaredThrowableException
        at com.sun.proxy.$Proxy75.persist(Unknown Source)
        ... 57 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_60]
        at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_60]
        at org.apache.aries.jpa.container.impl.EntityManagerProxyFactory$EMHandler.invoke(EntityManagerProxyFactory.java:31)
        ... 58 more
Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.aurimas.edi.entity.message.HL7Message.id
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)[142:org.hibernate.entitymanager:4.3.6.Final]
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)[142:org.hibernate.entitymanager:4.3.6.Final]
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683)[142:org.hibernate.entitymanager:4.3.6.Final]
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1187)[142:org.hibernate.entitymanager:4.3.6.Final]
        ... 62 more
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.aurimas.edi.entity.message.HL7Message.id
        at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:60)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:346)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4746)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4465)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:243)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.event.internal.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:511)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:116)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)[141:org.hibernate.core:4.3.6.Final]
        at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)[142:org.hibernate.entitymanager:4.3.6.Final]
        ... 62 more
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field com.aurimas.edi.entity.message.HL7Message.id to com.aurimas.edi.entity.message.HL7Message
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)[:1.8.0_60]
        at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)[:1.8.0_60]
        at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)[:1.8.0_60]
        at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)[:1.8.0_60]
        at java.lang.reflect.Field.get(Field.java:393)[:1.8.0_60]
        at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:57)[141:org.hibernate.core:4.3.6.Final]
        ... 73 more

重新启动 Karaf 后,此问题消失并持续存在。

我不想每次都重启 karaf。

我发现在我的捆绑包更新后我需要执行以下步骤:

    刷新 hibernate-osgi 包 重启我的包

然后一切都开始工作了,但我不想每次都刷新 hibernate-osgi 并重新启动我的包。

我正在使用 Apache Karaf 3.0.3、Hibernate 4.3.6、Java 1.8.0_60。

【问题讨论】:

【参考方案1】:

请注意,这在 Hibernate ORM OSGi 4.x 和 5.0.x 中是绝对预期的。重新启动应用程序包对 hibernate-osgi 和最终的 hibernate-core 具有灾难性的后果。在https://hibernate.atlassian.net/browse/HHH-9818 得到纠正之前(我们将尽快处理),Hibernate ORM OSGi 应该被视为静态,而不是动态响应 OSGi 捆绑事件。

【讨论】:

【参考方案2】:

您需要对 hibernate-bundle 进行刷新,因为它不知道更新后的捆绑包发生了变化,它仍然保留对旧捆绑包的引用。因此,更新始终也需要刷新其他捆绑包。 这是设计使然,因为 Update 只是更新 Bundle 本身,但不会触发解析所有其他依赖项的“更新”。因此,您必须在使用 refresh 命令自行解析捆绑包时触发该“更新”。这可以使用休眠捆绑包的 ID 或仅“刷新”来完成。第二个将更新您已安装的所有捆绑包的解析。

【讨论】:

以上是关于重新启动 karaf 所需的捆绑包更新的主要内容,如果未能解决你的问题,请参考以下文章

Windows 无法安装所需的文件。 请确保安装所需的所有文件可用,并重新启动安装。 错误代码: 0x800700B7

高效的 OSGi 开发工作流程

Apache Karaf 如何对要安装和启动的包进行排序?

下载的软件授权获取失败重新启动客户端什么意思?

重新创建现有打印机所需的 Powershell 脚本

捆绑安装在 Jenkins 管道上真的很慢(AWS EC2 实例)