lundi 8 juin 2015

Hibernate Lazy loading not work in OneToOne relation

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:

http://ift.tt/1Qjg5gJ

but nothing helps.(I cant use bytecode instrumentation)

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

Aucun commentaire:

Enregistrer un commentaire