Answer the question
In order to leave comments, you need to log in
Hibernate - why is the first level cache not working?
From the documentation: The
first level cache is always bound to the session object. Hibernate always uses this cache by default and cannot be disabled.
My code.
@Entity
@Table(name = "okof")
public class Okof {
@Id
protected Integer id;
@Column(name = "name")
private String name;
public Okof() {
}
...
}
@Repository
public class JpaOkofRepositoryImpl implements OkofRepository {
@PersistenceContext
private EntityManager em;
@Override
public List<Okof> getOkofList() {
return em.createQuery("SELECT o FROM Okof o ORDER BY o.code").getResultList();
}
...
}
public static void main(String[] args) {
try (GenericXmlApplicationContext appCtx = new GenericXmlApplicationContext()) {
appCtx.load("spring/spring-app.xml", "spring/spring-db.xml");
appCtx.refresh();
OkofRepository repository = appCtx.getBean(OkofRepository.class);
repository.getOkofList();
repository.getOkofList();
}
}
Hibernate:
/* SELECT
o
FROM
Okof o
ORDER BY
o.code */ select
okof0_.code as code1_1_,
okof0_.name as name2_1_
from
okof okof0_
order by
okof0_.code
Hibernate:
/* SELECT
o
FROM
Okof o
ORDER BY
o.code */ select
okof0_.code as code1_1_,
okof0_.name as name2_1_
from
okof okof0_
order by
okof0_.code
Answer the question
In order to leave comments, you need to log in
From the documentation: The
first level cache is always bound to the session object. Hibernate always uses this cache by default and cannot be disabled.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question