Hibernate Lazy加载在OneToOne关系中不起作用 [英] Hibernate Lazy loading not work in OneToOne relation

查看:634
本文介绍了Hibernate Lazy加载在OneToOne关系中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的公司,我们将一个旧应用程序从Hibernate 2迁移到Hibernate 4.
我的任务是将所有xml实体移动到注释。移动它后,OneToOne关系中的延迟加载停止工作。

In my company we migrated one old app from Hibernate 2 to Hibernate 4. My task was to move all xml entities to annotations. After moving it lazy loading in OneToOne relationship stop working.

entity a xml:

entity a xml:

<id name="entityAid" type="integer" column="entityAid_id">
<one-to-one name="entityB" entity-name="EntityB"
        property-ref="entityA" />

entity b xml:

entity b xml:

<property name="entityAid" type="integer" column="entityA_id" />
<many-to-one name="entityA" column="entityA_id" entity-name="EntityA" update="false" insert="false" />

我用代码移动了它:

实体a

 @OneToOne(fetch = FetchType.LAZY, mappedBy = "entityA")
 private EntityB storageRatecard;

实体b

@ManyToOne
@JoinColumn(name = "entityA_id", insertable = false, updatable = false)
private EntityA entityA;

现在,当我运行app延迟加载不起作用但在xml conf上工作。我发现:

Now when I run app lazy loading not work but worked on xml conf. I found:

制作OneToOne-关系懒惰

但没有任何帮助。(我不能使用字节码检测)

but nothing helps.(I cant use bytecode instrumentation)

我是什么做错了?为什么使用xml一切正常并且注释没有?

What I am doing wrong? Why with xml everything is ok and with annotations no?

推荐答案

mi的工作是懒惰的一对一反向关系。

What work for mi is Lazy one-to-one inverse relationships.

我读到了这个这里(这也是一个很好的教程如何使用它)。我希望它可以帮助一些人帮助我。

I read about this here (it is also a good tutorial how to use it). I hope it will help some one as it helps me.

这篇关于Hibernate Lazy加载在OneToOne关系中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆