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:
<id name="entityAid" type="integer" column="entityAid_id">
<one-to-one name="entityB" entity-name="EntityB"
property-ref="entityA" />
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" />
I moved it with code:
entity a
@OneToOne(fetch = FetchType.LAZY, mappedBy = "entityA")
private EntityB storageRatecard;
entity b
@ManyToOne
@JoinColumn(name = "entityA_id", insertable = false, updatable = false)
private EntityA entityA;
Now when I run app lazy loading not work but worked on xml conf. I found:
Making a OneToOne-relation lazy
but nothing helps.(I cant use bytecode instrumentation)
What I am doing wrong? Why with xml everything is ok and with annotations no?
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.