Вопрос

I just moved to Spring MVC for several days. Before that, I used to develop web project using JSF, EJB and JPA.

In EJB, we can use a stateful session bean(SFSB) with extended persistence context so that I can cache the entities in order to reduce database query. But in Spring MVC, once the entity is returned from a @Service bean, it becomes detached and cannot survive the next request. So I have to query database again in next request.

My question is how can I keep an entity managed by Entitymanager during many request?Thanks!

Это было полезно?

Решение

Use a 2nd level cache or session scoped beans, to keep entities in memory. Spring beans have mulplie different possible scopes.

Worth mentioning that keeping everything stateless makes scaling out easier. And adding state to anything http is always counter intuitive, to me at least.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top