문제

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