In Hibernate why is a @OneToOne associated @Entity not being returned from 2nd level cache?

Solution Verified - Updated -

Issue

  • 2nd level hibernate cache is not working when Foreign Key OneToOne mapping is used. InverseEntity.getOwningEntity() doesn't hit the cache.

Environment

  • JBoss Enterprise Application Platform (EAP)

    • 4.3.0 CP06
  • Hibernate 3.2.4 SP1 (Included in the EAP)

  • Model being OwningEntity 1--1 InverseEntity (bidirectionnal OneToOne)
  • Owning side of the association

    public class OwningEntity {
    ...
    @OneToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "ID_CHUTE", nullable = false)
      public  InverseEntity getInverseEntity() {...}
    ...
    }
    
  • InverseEntity.java

    public class  InverseEntity {
          ...
    @OneToOne(mappedBy =  "inverseEntity", fetch = FetchType.LAZY)
    public OwningEntity getOwningEntity () {...}
    

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content