1

The project use hibernate 4.2.0 and spring 3.1.3.

I'm adding redis for second cache in my project. There are class A,B,C. Their relation is a.getB().getC() The code like:

Class A{
    @ManyToOne(targetEntity = InternalOrganizationImpl.class, fetch = FetchType.LAZY)
    @Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE })
    @JoinColumn(name = "bid")
    private B b;
}

Now i get object A from database and put it into redis. Then i get it from redis ,but when i use a.getB().getC(),throw the Exception that could not initialize proxy - no Session

I have read the question How to fix org.hibernate.LazyInitializationException...

set the property is effect,but it makes project too slow

<prop key="hibernate.enable_lazy_load_no_trans">true</prop>

the annotion @Transcation not work

Is there any butter solution?

Rookie lx
  • 11
  • 1

0 Answers0