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