This page (revision-12) was last changed on 18-Aug-2014 15:03 by Dieter Käppel

This page was created on 13-Dec-2010 16:31 by Dieter Käppel

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
12 18-Aug-2014 15:03 7 KB Dieter Käppel to previous
11 18-Aug-2014 15:03 5 KB Dieter Käppel to previous | to last
10 04-Jul-2014 13:19 4 KB Dieter Käppel to previous | to last
9 29-Dec-2012 13:07 3 KB Dieter Käppel to previous | to last
8 30-Nov-2012 13:40 5 KB Dieter Käppel to previous | to last
7 24-Nov-2012 11:54 5 KB Dieter Käppel to previous | to last
6 23-Nov-2012 21:02 4 KB Dieter Käppel to previous | to last
5 23-Nov-2012 08:12 4 KB Dieter Käppel to previous | to last
4 01-Nov-2012 23:48 3 KB Dieter Käppel to previous | to last
3 15-Dec-2010 13:23 1 KB Dieter Käppel to previous | to last
2 15-Dec-2010 11:00 1 KB Dieter Käppel to previous | to last
1 13-Dec-2010 16:31 300 bytes Dieter Käppel to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 36 changed one line
!Spring Open EntityManager Once in View Pattern
!Spring Open EntityManager once in View Pattern
At line 48 added 48 lines
!Spring Open EntityManager in Session
Nicht getestet ob das praktikabel ist.
{{{
public class OpenEntityManagerInSessionFilter extends OncePerRequestFilter {
public static final String ENTITY_MANAGER_FACTORY_NAME = "entityManagerFactory";
public static final String ENTITY_MANAGER_NAME = "entityManager";
private String entityManagerFactoryBeanName = ENTITY_MANAGER_FACTORY_NAME;
public void setEntityManagerFactoryBeanName(String entityManagerFactoryBeanName) {
this.entityManagerFactoryBeanName = entityManagerFactoryBeanName;
}
public String getEntityManagerFactoryBeanName() {
return entityManagerFactoryBeanName;
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
EntityManagerFactory entityManagerFactory = lookupEntityManagerFactory();
boolean participate = false;
try {
if (TransactionSynchronizationManager.hasResource(entityManagerFactory)) {
participate = true;
} else {
EntityManager entityManager = (EntityManager)request.getSession().getAttribute(ENTITY_MANAGER_NAME);
if (entityManager == null) {
entityManager = entityManagerFactory.createEntityManager();
request.getSession().setAttribute(ENTITY_MANAGER_NAME, entityManager);
}
TransactionSynchronizationManager.bindResource(
entityManagerFactory, new EntityManagerHolder(entityManager));
}
filterChain.doFilter(request, response);
} finally {
if (!participate)
TransactionSynchronizationManager.unbindResource(entityManagerFactory);
}
}
protected EntityManagerFactory lookupEntityManagerFactory() {
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
return (EntityManagerFactory) wac.getBean(getEntityManagerFactoryBeanName(), EntityManagerFactory.class);
}
}
}}}