1

I use ehcache and hibernate 3.6.7 Final. This a pseudo code sample that reveals problem with caching.

@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class A{    

    long id;    

    @OneToMany(mappedBy = "aId", targetEntity = B.class, fetch = FetchType.LAZY)
    @Fetch(value = FetchMode.JOIN)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    protected Set<B> fieldB;
}    


@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class B { 

    long id;

    long bId; 
}

1) First time when I load entity A from hibernate it does not read fieldB. And this is ok - cause FetchType.LAZY is set.

2) Second time when I load entity A I see sql queries retrieving entity A JOIN entity B.

3)If remove @Fetch(value = FetchMode.JOIN) point 2 will not be performed.

So the question is this bug or feature? And how can I avoid such latent things.

1
  • You can try asking also on the Hibernate Forums. And if you are brave enough (and have time), debug using Hibernate source code. Commented Jun 15, 2012 at 12:21

1 Answer 1

1

You have two conflicting fetches, you definitely do not want to specify the fetch on the column and the @Fetch annotation as it will provide unpredicatable behavior.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.