0
我看到有很多问题,以不同的方式在堆栈溢出中提到过同样的问题。我在Hibernate论坛上看到了这个问题,他们提到它会起作用。我们可以参考这个link休眠5.2.9:@Basic(fetch = FetchType.LAZY)不起作用
基于此链接,延迟加载应该基本属性工种一样的byte []
我使用Hibernate的版本5.2.9 + PostgreSQL的DB
我的实体模型看起来像这
@Entity
@Table
public class ResourceFileEntity {
@Id
@GeneratedValue
long id;
@Column
private String storageType;
@Column
private String path;
@Lob
@Basic(fetch = FetchType.LAZY)
@Column
byte[] fileContent;
// removed getters/setter for readibility
}
代码来获取实体
public ResourceFileEntity fetchEntity(long jId) throws IOException {
Session session = factory.openSession();
ResourceFileEntity entity = null;
Transaction tx = null;
try {
tx = session.beginTransaction();
entity = session.find(ResourceFileEntity.class, jId);
System.out.println(Hibernate.isPropertyInitialized(entity, "fileContent"));
tx.commit();
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
e.printStackTrace();
} finally {
session.close();
}
return entity;
}
很多人都提到过关于字节码增强的问题,我的确尝试在我的项目build.gradle中使用@LazyGroup,但仍然没有运气。
对此的任何输入都会有很大的帮助!
+1。这可能是一个错误。如果您更喜欢JPA API,那么您也可以使用[JPA测试案例模板](http://in.relation.to/2016/01/14/hibernate-jpa-test-case-template/)。 –
当然。将添加测试用例。感谢Vlad和Alex的回复 – Mohnish
我在HHH-10929中添加了测试用例 – Mohnish