gpt4 book ai didi

java - org.hibernate.HibernateException [org.postgresql.util.PSQLException : Large Objects may not be used in auto-commit mode.]

转载 作者:行者123 更新时间:2023-12-01 09:40:14 28 4
gpt4 key购买 nike

我知道这个问题可能之前已经被问过,但我的问题的不同之处在于我正在使用扩展的PersistenceUnit,而且我也不是管理事务的人,因为服务器负责用于管理它。

顺便说一句,我正在将 JPA(2.1) 与 hibernate(4.3.10) 提供程序、PostgreSQL(9.5) DB 和 liberty 服务器一起使用

这是我在浏览器中得到的 enter image description here

这是我的简单 View 中的实体

@Entity
public class GeoArea{
private Integer id;//Auto Generated
private String name;

private Set<TourismOrganization> organizations;

//getter and setter methods

@ManyToMany(mappedBy = "geoAreas")
public Set<TourismOrganization> getOrganizations() {
return organizations;
}

public void setOrganizations(Set<TourismOrganization> organizations) {
this.organizations = organizations;
}
}
<小时/>
@Entity
public class TourismOrganization{
private Integer id;//Auto Generated
private String name;

private BinaryContent logo;
private Set<TourismGeoArea> geoAreas;

//other getter and setter methods

@ManyToMany
public Set<TourismGeoArea> getGeoAreas() {
return geoAreas;
}

public void setGeoAreas(Set<TourismGeoArea> geoAreas) {
this.geoAreas = geoAreas;
}

@OneToOne(fetch = FetchType.EAGER, optional = true, cascade = { CascadeType.REMOVE }, orphanRemoval = true)
public BinaryContent getLogo() {
return logo;
}

public void setLogo(BinaryContent logo) {
this.logo = logo;
}
}
<小时/>
@Entity
public class BinaryContent{
private Integer id;//Auto Generated
private String contentType;

private byte[] data;

//other getter and setter methods

@Lob
@Column(length = 16000000) // This should generate a medium blob
@Basic(fetch = FetchType.LAZY) // I've read this is default, but anyway...
public byte[] getData() {
return data;
}

public void setData(byte[] data) {
this.data = data;
}

}

在 xhtml 页面中使用 >> geoArea.organizations 获取 geoArea 下的组织时,您知道如何解决此问题吗?

最佳答案

我知道这个问题是在一个月前提出的,但我想分享我的解决方案,因为这里没有人回答我的问题。

顺便说一句,我的解决方案是在其 getter 上使用 byte[] 而没有 @Lob ,这样这将在 postgre 数据库表中生成列 bytea 不再是 oid

这是我现在使用的代码,以避免在浏览器中触发的大对象可能无法在自动提交模式下使用......异常并阻止页面按预期工作

@Entity
public class BinaryContent{
private Integer id;//Auto Generated
private String contentType;

private byte[] data;

//other getter and setter methods

//@Lob >> remember that i am not using it anymore to avoid the exception on the browser
@Column(length = 16000000) // This should generate a medium blob
@Basic(fetch = FetchType.LAZY) // I've read this is default, but anyway...
public byte[] getData() {
return data;
}

public void setData(byte[] data) {
this.data = data;
}

}

Note >> u must delete oid column by hand if it was already generated before using @Lob if you are using hibernate.hbm2ddl.auto=update in your persistence.xml as it will not help to update the column from oid to be type bytea and it will consider oid is fine but sure you can use hibernate.hbm2ddl.auto=create-drop to drop and create the tables again and this will generate the column in bytea type

关于java - org.hibernate.HibernateException [org.postgresql.util.PSQLException : Large Objects may not be used in auto-commit mode.],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38511205/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com