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 2 lines
!!!Spring Open EntityManager once in View Pattern
web.xml:
!!!Lazy-Loading und Transaction Management
Es ist praktikabel, das JPA Transaction Management zusammen mit Spring zu verwenden (Annotation <tx:annotation-driven/>). Für die View kann dann der OpenEntityManagerInViewFilter verwendet werden, um Paging und Lazy-Loading zu realisieren:
At line 40 changed 2 lines
<filter-name>EntityManagerFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
At line 44 changed one line
<filter-name>EntityManagerFilter</filter-name>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
At line 49 changed 2 lines
!!!Spring Open EntityManager in Session
Es ist eher praktikabel, das JPA Transaction Management zusammen mit Spring zu verwenden (Annotation <tx:annotation-driven/>). Für die View kann dann der OpenEntityManagerInViewFilter verwendet werden, um Paging und Lazy-Loading zu realisieren.
Der EntityManager kann allerdings die Session nur öffnen, wenn der Hibernate-Parameter dafür gesetzt ist (etwa in der persistence.xml):
At line 52 removed 2 lines
Dennoch hier der Code:
At line 55 changed 43 lines
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);
}
}
<property name="hibernate.enable_lazy_load_no_trans" value="true"/>