2016-03-17 58 views
2

JPA相當新穎,我有一條駱駝路線使用它,所以我在準確理解我的問題以及如何解決問題時遇到了一些麻煩。經過一堆更多的測試後,我發現這個錯誤似乎只發生在我的karaf容器中重新啓動我的包之後。如果我第一次加載容器並安裝它,一切似乎都運行良好。我將自己的特徵文件信息Camel Jpa Hibernate屬性訪問異常在Karaf容器中重新啓動包後

Version information: 
JBoss 6.2.1 
Camel Version: 2.15.1.redhat-621084 
Hibernate Version: 4.2.20.Final-redhat-1 


from(exceptionInputQueue).routeId("PackageExceptionRoute") 
     .unmarshal(exceptionDataFormat).id("UnmarshalException") 
     .convertBodyTo(ExceptionEntity.class).id("ExceptionModelToEntity") 
     .to("jpa:" + ExceptionEntity.class.getName()).id("PersistExceptionEntity"); 

@Entity 
@Table(name = "Exception") 
public class ExceptionEntity implements Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    @Column(name = "PackageTrackingNumber", updatable = false, nullable = false, length = 18) 
    private String packageTrackingNumber; 

    @Temporal(TemporalType.TIMESTAMP) 
    @Column(name = "ExceptionTimestamp") 
    private Date exceptionTimestamp; 

    @Column(name = "InformationSourceCode", length = 2) 
    private String informationSourceCode; 

    @Column(name = "ExceptionReasonCode", length = 2) 
    private String exceptionReasonCode; 

    @Column(name = "ExceptionResolutionCode", length = 2) 
    private String exceptionResolutionCode; 

    @Column(name = "ExceptionStatusCode", length = 2) 
    private String exceptionStatusCode; 

    @Column(name = "ExceptionCountryCode", length = 2) 
    private String exceptionCountryCode; 

    @Column(name = "ExceptionLocationNumber", length = 5) 
    private String exceptionLocationNumber; 

    //... hashcode, equals, toString, and getters/setters excluded 
} 

駱駝語境

<camelContext id="PackageExceptionRouteContext" xmlns="http://camel.apache.org/schema/spring" 
    streamCache="true"> 
    <routeBuilder ref="PackageExceptionRoute" /> 
</camelContext> 

<bean id="PackageExceptionRoute" class="com.ups.ops.cipe.internal.route.PackageExceptionRoute"> 
    <property name="exceptionInputQueue" value="ibmmq:queue:myQueueName" /> 
    <property name="exceptionDataFormat" ref="GsonDataFormat" /> 
</bean> 

<bean id="GsonDataFormat" class="org.apache.camel.component.gson.GsonDataFormat"> 
    <property name="unmarshalType" 
     value="com.ups.ops.cipe.internal.eud.model.EudExceptionModel" /> 
    <property name="dateFormatPattern" value="yyyy-MM-dd' 'HH:mm:ss.SSS' 'X" /> 
</bean> 

<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent"> 
    <property name="entityManagerFactory" ref="entityManagerFactory" /> 
    <property name="transactionManager" ref="transactionManager" /> 
</bean> 

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="persistenceUnitName" value="PackageException" /> 
    <property name="jpaVendorAdapter" ref="jpaAdapter" /> 
    <property name="jpaDialect" ref="jpaDialect" /> 
    <property name="dataSource" ref="dataSource" /> 
</bean> 

<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
    <property name="generateDdl" value="true" /> 
    <property name="showSql" value="false" /> 
    <property name="database" value="SQL_SERVER" /> 
    <property name="databasePlatform" value="org.hibernate.dialect.SQLServer2012Dialect" /> 
</bean> 

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
    <property name="entityManagerFactory" ref="entityManagerFactory" /> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="jpaDialect" ref="jpaDialect" /> 
</bean> 

<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /> 

<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource"> 
    <property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" /> 
    <property name="url" value="myDBURL" /> 
    <property name="username" value="myUser" />  
    <property name="password" value="myPass" />   
</bean> 

<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> 
    <property name="transactionManager" ref="transactionManager" /> 
</bean> 

<bean id="ibmmq" class="org.apache.camel.component.jms.JmsComponent" 
    destroy-method="doStop"> 
    <property name="transacted" value="false" /> 
    <property name="concurrentConsumers" value="1" /> 
    <property name="maxConcurrentConsumers" value="1" /> 
    <property name="acceptMessagesWhileStopping" value="true" /> 
    <property name="acknowledgementModeName" value="CLIENT_ACKNOWLEDGE" /> 
    <property name="cacheLevelName" value="CACHE_CONSUMER" /> 
    <property name="connectionFactory"> 
     <bean class="org.springframework.jms.connection.SingleConnectionFactory" 
      destroy-method="destroy"> 
      <constructor-arg> 
       <bean class="com.ibm.mq.jms.MQQueueConnectionFactory"> 
        <property name="transportType" value="1" /> 
        <property name="channel" value="myChannel" /> 
        <property name="hostName" value="myHostname" /> 
        <property name="port" value="myPort" /> 
        <property name="queueManager" value="myQueueManager" /> 
       </bean> 
      </constructor-arg> 
     </bean> 
    </property> 
</bean> 

的persistence.xml

<persistence-unit name="PackageException" transaction-type="RESOURCE_LOCAL"> 
    <class>com.ups.ops.cipe.external.exception.entity.ExceptionEntity</class> 
    <properties>    
     <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2012Dialect" /> 
     <property name="hibernate.archive.autodetection" value="class" /> 
     <property name="hbm2ddl.auto" value="update" /> 
    </properties> 
</persistence-unit> 

特性文件

<feature name="myFeature-all" version="${project.version}"> 
    <feature>camel-gson</feature> 
    <feature>camel-quartz</feature> 
    <feature>camel-jpa</feature> 
    <feature>camel-jgroups</feature> 
    <feature>hibernate</feature> 
    <bundle>mvn:com.fun.my.project/PackageExceptionBundle/${project.version}</bundle> 
</feature> 

堆棧跟蹤

javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.ups.ops.cipe.external.exception.entity.ExceptionEntity.packageTrackingNumber 
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)[277:org.hibernate.entitymanager:4.2.20.Final-redhat-1] 
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)[277:org.hibernate.entitymanager:4.2.20.Final-redhat-1] 
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316)[277:org.hibernate.entitymanager:4.2.20.Final-redhat-1] 
    at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:898)[277:org.hibernate.entitymanager:4.2.20.Final-redhat-1] 
    at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_66] 
    at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_66] 
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:366)[261:org.apache.servicemix.bundles.spring-orm:3.2.12.RELEASE_2] 
    at com.sun.proxy.$Proxy138.merge(Unknown Source)[:] 
    at org.apache.camel.component.jpa.JpaProducer$1.save(JpaProducer.java:102)[264:org.apache.camel.camel-jpa:2.15.1.redhat-621084] 
    at org.apache.camel.component.jpa.JpaProducer$1.doInTransaction(JpaProducer.java:78)[264:org.apache.camel.camel-jpa:2.15.1.redhat-621084] 
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)[140:org.apache.servicemix.bundles.spring-tx:3.2.12.RELEASE_2] 
    at org.apache.camel.component.jpa.JpaProducer.process(JpaProducer.java:61)[264:org.apache.camel.camel-jpa:2.15.1.redhat-621084] 
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:167)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:304)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:162)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)[146:org.apache.camel.camel-core:2.15.1.redhat-621084] 
    at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103)[150:org.apache.camel.camel-jms:2.15.1.redhat-621084] 
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562)[141:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_2] 
    at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500)[141:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_2] 
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468)[141:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_2] 
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)[141:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_2] 
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)[141:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_2] 
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1101)[141:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_2] 
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1093)[141:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_2] 
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:990)[141:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_2] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_66] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_66] 
    at java.lang.Thread.run(Thread.java:745)[:1.8.0_66] 
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.ups.ops.cipe.external.exception.entity.ExceptionEntity.packageTrackingNumber 
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:62)[279:org.hibernate.core:4.2.20.Final-redhat-1] 
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:344)[279:org.hibernate.core:4.2.20.Final-redhat-1] 
    at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4550)[279:org.hibernate.core:4.2.20.Final-redhat-1] 
    at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:158)[279:org.hibernate.core:4.2.20.Final-redhat-1] 
    at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:86)[279:org.hibernate.core:4.2.20.Final-redhat-1] 
    at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:833)[279:org.hibernate.core:4.2.20.Final-redhat-1] 
    at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:817)[279:org.hibernate.core:4.2.20.Final-redhat-1] 
    at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:821)[279:org.hibernate.core:4.2.20.Final-redhat-1] 
    at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:889)[277:org.hibernate.entitymanager:4.2.20.Final-redhat-1] 
    ... 33 more 
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field com.ups.ops.cipe.external.exception.entity.ExceptionEntity.packageTrackingNumber to com.ups.ops.cipe.external.exception.entity.ExceptionEntity 
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)[:1.8.0_66] 
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)[:1.8.0_66] 
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)[:1.8.0_66] 
    at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)[:1.8.0_66] 
    at java.lang.reflect.Field.get(Field.java:393)[:1.8.0_66] 
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59)[279:org.hibernate.core:4.2.20.Final-redhat-1] 
    ... 41 more 
+0

確定您的POJO類中有一個名爲'getPackageTrackingNumber()'的公共方法? – Vihar

+0

是的,我爲每個變量都包含getter和setter,包括PackageTrackingNumber:public String getPackageTrackingNumber(){return packageTrackingNumber;} –

+0

也許這個鏈接會幫助你http://stackoverflow.com/questions/27771440/javax-persistence-persistenceexception- org-hibernate-propertyaccessexception-c在hibernate.properties文件或persistence.xml文件中添加hibernate.classloading.use_current_tccl_as_parent = false。 –

回答

0

經過大量的樂趣後,OSGI和Hibernate看起來並不是很好。我發現一些JIRA門票的增強功能可以改善這一點。現在,我正在對應用程序卸載和重新安裝之間的hibernate相關軟件包發佈刷新命令。

https://hibernate.atlassian.net/browse/HHH-9818

https://hibernate.atlassian.net/browse/HHH-8501

指出:休眠-OSGI 6是使其正常工作需要。

+1

Hibernate 5現在有一個非常好的OSGi集成,請參閱http://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html#osgi –

+0

真棒夢幻般的鏈接。很高興知道,一旦我更新到4.3版本,它看起來像被照顧了。我將不得不檢查Redhat補丁程序週期以查看FUSE平臺是否會捆綁該修復程序。謝謝你的信息! –

+1

其實現在hibernate直接提供了karaf和jboss的保險絲功能文件https://repo1.maven.org/maven2/org/hibernate/hibernate-osgi/5.1.0.Final/hibernate-osgi-5.1.0.Final -karaf.xml –

相關問題