[英]Does a CrudRepository delete also remove underlying large objects of Blob fields
我有一个带有@Lob
注释的Blob
字段的实体:
@Entity
public class Entry {
@Id
@GeneratedValue
private Long tid;
@Lob
private Blob content;
}
content
是使用 Hibernate 的LobCreator创建的,然后使用 JPA CrudRepository保存实体:
public Entry save(Entry template, InputStream source) {
Session session = entityManager.unwrap(Session.class);
content = Hibernate.getLobCreator(session).createBlob(source);
template.setContent(content);
return entryRepository.save(template);
}
当使用 PostgreSQL 作为底层数据库时,给定Entry
的content
列将不包含实际的大对象本身,而是一个引用它的oid
。
假设我现在正在使用CrudRepository
来delete
给定的实体,我想知道我是否可以确定不仅行本身将被删除,而且大对象也会被删除,或者我是否会留下一个孤立的大对象。
我可以使用PostgresSQL 特定的功能解决这个问题,但如果可能的话,我想坚持使用与数据库无关的 Hibernate 方法。
public class FileData {
@Lob
@Column(name = "file_data")
private Blob fileDataBlob;
public void freeFileDataBlob() throws SQLException {
if (this.fileDataBlob != null){
this.fileDataBlob.truncate(0L);
this.fileDataBlob.free();
this.fileDataBlob = null;
LOG.info("freeFileDataBlob() successful");
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.