我需要你的帮助。我想从java写入ProstgreSQL,但表格都是空的。检查完日志后,我发现了这个:
[#|2018-03-29T09:13:52.689+0200|WARNING|oracle-glassfish3.1.2|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=151;_ThreadName=__ejb-thread-pool1;|javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5240)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5138)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4926)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2047)
at com.sun.ejb.containers.EjbAsyncTask.call(EjbAsyncTask.java:114)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.4.v20160520-8886999): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
Error Code: 0
Call: INSERT INTO cats (ID, CAT, CAT_C, CAT_E, CAT_CE, CAT_L, CAT_LV, CAT_N, CAT_O, CAT_P, CAT_R, CAT_T) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
bind => [12 parameters bound]
Query: InsertObjectQuery(com.lel.b2v.ddd.model.CategoryDataDb@181bce9c)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:785)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.flush(EntityManagerWrapper.java:418)
at com.lel.b2v.ddd.service.CategoryCacheUpdaterHelper.updateDatabase(CategoryCacheUpdaterHelper.java:174)
at com.lel.b2v.ddd.service.CategoryCacheUpdaterHelper.addCategoriesForAllLanguagesToDb(CategoryCacheUpdaterHelper.java:117)
at com.lel.b2v.ddd.service.CategoryCacheUpdaterHelper.updateCache(CategoryCacheUpdaterHelper.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5413)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5385)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5373)
at com.sun.ejb.containers.EjbAsyncTask.call(EjbAsyncTask.java:101)
... 4 more
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.4.v20160520-8886999): org.eclipse.persistence.exceptions.DatabaseException
我搜索了大约2天才发现问题,但我找不到。
这是执行更新的代码:
private void updateDb(final List<CategoryDataDb> mappedCategories) {
if (!mappedCategories.isEmpty()) {
// Remove all entries when we know the result
this.em.createQuery("DELETE FROM CatDb r", CategoryDataDb.class).executeUpdate();
for (final CategoryDataDb newDbCategory : mappedCategories) {
this.em.merge(newDbCategory);
}
} else {
LOGGER.warn(
"Error.");
}
}
&#13;