Java Hibernate 5.2.9:@Basic(fetch=FetchType.LAZY)不工作
我看到前面在stack overflow中有很多问题是以不同的方式提出的。我在Hibernate论坛上看到了其中一个问题,他们提到它会起作用。我们可以参考这个 基于此链接,延迟加载应该适用于基本属性类型,如byte[] 我使用的是hibernate版本5.2.9+postgresql数据库 我的实体模型如下所示Java Hibernate 5.2.9:@Basic(fetch=FetchType.LAZY)不工作,java,hibernate,postgresql-9.4,Java,Hibernate,Postgresql 9.4,我看到前面在stack overflow中有很多问题是以不同的方式提出的。我在Hibernate论坛上看到了其中一个问题,他们提到它会起作用。我们可以参考这个 基于此链接,延迟加载应该适用于基本属性类型,如byte[] 我使用的是hibernate版本5.2.9+postgresql数据库 我的实体模型如下所示 @Entity @Table public class ResourceFileEntity { @Id @GeneratedValue long id; @Column privat
@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,但仍然没有成功
在这方面的任何意见都会有很大的帮助 您可能遇到了。尽管这还需要通过使用Hibernate的自包含测试用例来证明。如果您认为有问题,可能值得创建一个?+1。这可能是一只虫子。如果您更喜欢JPAAPI,那么您也可以使用。将添加测试用例。感谢Vlad和Alex的回复。我已经在HHH-10929中添加了测试用例。Jira上的回复表明您的配置有问题。建议的更改是否解决了您的问题?是的,它解决了…我的实体位于src/test/java中。它应该在src/main/java和IDE中,不知何故字节码增强并没有起作用。我通过命令行和它的工作方式运行它。我也能懒洋洋地加载一个一个和多个一个的关联。谢谢你的帮助!