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 of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.