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 added 60 lines
!!Local Container Manager vs. Local Entity Manager
Neben dem LocalContainerEntityManagerFactoryBean gibt es noch den LocalEntityManagerFactoryBean, der einfacher zu konfigurieren und zunächst ohne Container, das heißt JNDI auskommt:
{{{
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean" lazy-init="true">
<property name="persistenceUnitName" value="subflowDb"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.connection.url">jdbc:hsqldb:file:${project.build.directory}/hsql/data</prop>
<prop key="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.connection.username">sa</prop>
<prop key="hibernate.connection.password"></prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
}}}
Allerdings ist es auch möglich, den LocalContainerEntityManagerFactoryBean lokal zu konfigurieren, sodass er z.B. aus einem JUnit-Test mit Spring heraus läuft:
{{{
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitManager">
<bean id="persistenceUnitManager" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocations" value="classpath*:META-INF/persistence.xml"/>
<property name="defaultDataSource" ref="dataSource"/>
</bean>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="maxActive" value="100"/>
<property name="maxIdle" value="30"/>
<property name="maxWait" value="16000"/>
<property name="minIdle" value="0"/>
</bean>
}}}
Der Test sieht dann so aus:
{{{
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:META-INF/testApplicationContext.xml")
// @TransactionConfiguration(defaultRollback = false)
public class SpringDBTest {
@Test
@Transactional
public void test() {
Criteria criteria = ((Session)entityManager.getDelegate()).createCriteria(Test.class);
...
}
}
}}}