Karaf - 持久化简单POJO时的例外

时间:2017-01-09 12:04:16

标签: java hibernate jpa apache-karaf karaf

我正在拧一些我在Karaf下部署的代码。 我试图将一个简单的POJO对象保存到表中。

我在下面得到例外。

这个reportRequestID是PK字段,我认为它已正确注释。

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ReportRequestID", unique = true, nullable = false)
public Integer getReportRequestID() {
    return reportRequestID;
}

public void setReportRequestID(Integer reportRequestID) {
    this.reportRequestID = reportRequestID;
}

数据库表没有外键。我这样说是因为我看到堆栈跟踪有ForeignKeys.isTransient,我觉得很奇怪。

所以我不知道这里有什么问题。我试图谷歌搜索这个错误,我发现很多点击,但我找不到任何与我的用例真正相关的东西。

非常感谢任何帮助。

    javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.hibu.microservices.dataaccess.sql.bean.KeywordReportQueue.reportRequestID
            at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
            at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
            at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683)
            at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1187)
            at com.hibu.microservices.dataaccess.sql.dao.KeywordReportQueueDao.insertCustomerGoogleReportRequest2(KeywordReportQueueDao.java:118)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            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.hibu.microservices.dataaccess.sql.dao.$KeywordReportQueueDao1640762817.insertCustomerGoogleReportRequest2(Unknown Source)
            at com.hibu.microservices.impl.customer.CustomerGenerateGoogleReportServiceImpl.requestReport(CustomerGenerateGoogleReportServiceImpl.java:31)
            at com.hibu.microservices.impl.customer.CustomerGenerateGoogleReportServiceImpl.generateReport(CustomerGenerateGoogleReportServiceImpl.java:54)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:181)
            at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:97)
            at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:200)
            at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99)
            at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
            at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
            at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
            at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
            at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)
            at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
            at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
            at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
            at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
            at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)
            at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:212)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
            at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:268)
            at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
            at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
            at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)
            at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
            at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
            at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
            at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
            at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:287)
            at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
            at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
            at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
            at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
            at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)
            at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
            at org.eclipse.jetty.server.Server.handle(Server.java:499)
            at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
            at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
            at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
            at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
            at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
            at java.lang.Thread.run(Thread.java:745)
    Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.hibu.microservices.dataaccess.sql.bean.KeywordReportQueue.reportRequestID
            at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:192)
            at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:346)
            at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4746)
            at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4465)
            at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:243)
            at org.hibernate.event.internal.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:511)
            at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:116)
            at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
            at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
            at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
            at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)
            at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)
            ... 52 more
    Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@6e91316a
            at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:169)
            ... 63 more

在我的karaf.log文件中,我也看到了这一点。

java.lang.ClassNotFoundException: Unable to load class 'org.hibernate.proxy.HibernateProxy' because the bundle wiring for com.hibu.microservices.data-access is no longer valid.

我不知道它是否相关或如何解决它。

1 个答案:

答案 0 :(得分:0)

我刚刚通过改变hibernate方言值来解决这个问题。

<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>

<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServer2008Dialect"/>

请注意,我使用的是SQL Server 2008 DB。