我试图保留具有映射的@Persistent InputStream字段的记录。 上下文是:JDK 1.8,LiferayPortal on Tomee 1.7.1(OpenJPA 2.4-patch)。对于被Liferay污染的堆栈跟踪感到抱歉。
@Entity
@Table(name = "file_entries")
public class FileEntry implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length = 120)
private String createdBy;
@Temporal(TemporalType.TIMESTAMP)
private Date created;
@Column(length = 120)
private String modifiedBy;
@Temporal(TemporalType.TIMESTAMP)
private Date modified;
@Column(length = 200)
private String title;
@Column(length = 2000)
private String description;
@Column(length = 240)
private String filename;
@Column(length = 60)
private String extension;
@Column(length = 20)
private String version;
@Column(length = 240)
private String contentType;
@Persistent(fetch = FetchType.LAZY)
private InputStream content;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public String getModifiedBy() {
return modifiedBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
public Date getModified() {
return modified;
}
public void setModified(Date modified) {
this.modified = modified;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getFilename() {
return filename;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getExtension() {
return extension;
}
public void setExtension(String extension) {
this.extension = extension;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public InputStream getContent() {
return content;
}
public void setContent(InputStream content) {
this.content = content;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
}
坚持下去:
logo = new FileEntry();
logo.setContent(new FileInputStream("some_local_file"));
entityService.persist(logo);
我收到以下异常。
<openjpa-2.4.0-nonfinal-1598334-r422266:1599166 fatal general error> org.apache.openjpa.persistence.PersistenceException: The transaction has been rolled back. See the nested exceptions for details on the errors that occurred.
at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2370)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2207)
at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2105)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1876)
at org.apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java:1045)
at org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:663)
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:483)
at org.zeroturnaround.jrebel.integration.openjpa.EntityManagerFactoryWrapper$ReloadingMethodHandler.invoke(EntityManagerFactoryWrapper.java:135)
at com.sun.proxy.$Proxy619.flush(Unknown Source)
at org.apache.openejb.persistence.JtaEntityManager.flush(JtaEntityManager.java:202)
at com.computas.generic.service.SimpleEntityService.persist(SimpleEntityService.java:37)
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:483)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
at sun.reflect.GeneratedMethodAccessor585.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:227)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:194)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:308)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:303)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:92)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:308)
... 171 more
Caused by: <openjpa-2.4.0-nonfinal-1598334-r422266:1599166 fatal general error> org.apache.openjpa.persistence.PersistenceException: can't call setAutoCommit when the connection is JtaManaged
at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4998)
at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4958)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:134)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:108)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:60)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:185)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:96)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:77)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:732)
at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
... 204 more
Caused by: java.sql.SQLException: can't call setAutoCommit when the connection is JtaManaged
at org.apache.openejb.resource.jdbc.managed.local.ManagedConnection.forbiddenCall(ManagedConnection.java:185)
at org.apache.openejb.resource.jdbc.managed.local.ManagedConnection.invokeUnderTransaction(ManagedConnection.java:162)
at org.apache.openejb.resource.jdbc.managed.local.ManagedConnection.invoke(ManagedConnection.java:93)
at com.sun.proxy.$Proxy618.setAutoCommit(Unknown Source)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.setAutoCommit(DelegatingConnection.java:167)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.setAutoCommit(DelegatingConnection.java:167)
at org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.setAutoCommit(ConfiguringConnectionDecorator.java:117)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.setAutoCommit(DelegatingConnection.java:167)
at org.apache.openjpa.lib.jdbc.DelegatingConnection.setAutoCommit(DelegatingConnection.java:167)
at org.apache.openjpa.jdbc.sql.PostgresDictionary.insertPostgresBlob(PostgresDictionary.java:627)
at org.apache.openjpa.jdbc.sql.PostgresDictionary.insertBlobForStreamingLoad(PostgresDictionary.java:614)
at org.apache.openjpa.jdbc.meta.strats.LobFieldStrategy.insert(LobFieldStrategy.java:100)
at org.apache.openjpa.jdbc.meta.FieldMapping.insert(FieldMapping.java:623)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.insert(AbstractUpdateManager.java:238)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.populateRowManager(AbstractUpdateManager.java:165)
... 208 more
持久性单元声明是:
<persistence-unit name="uefiscdi" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>uefiscdiDS</jta-data-source>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
<property name="openjpa.jdbc.DBDictionary" value="postgres" />
<property name="openjpa.Log" value="DefaultLevel=INFO, Tool=INFO" />
</properties>
</persistence-unit>
数据源声明是:
<Resource id="uefiscdiDS" type="DataSource">
JdbcDriver org.postgresql.Driver
JdbcUrl jdbc:postgresql://localhost:5432/db_name
UserName user_name
Password user_password
JtaManaged true
DefaultAutoCommit false
</Resource>
我尝试使用DefaultAutoCommit true / false / not声明...同样的异常。
答案 0 :(得分:0)
只是在黑暗中拍摄,但您是否尝试过调用em.persist(...)
而不是em.merge(..)
?
如果这不起作用,如果您在某处发布完整堆栈跟踪可能会有所帮助。我担心你可能会把这些重要部分剪掉。