Network Deployment (Distributed operating systems), v8.0 > Applications > Spring applications > Spring Framework


Data access and the Spring Framework

For Spring beans to access a data source, configure those beans so that the Spring Framework delegates to, and integrates with, the WAS runtime correctly.

The Spring Framework wraps Spring beans with a container-management layer that, in an enterprise application environment, delegates to the underlying enterprise application runtime. The following sections describe what to consider when you configure Spring beans that access a data source.


Access to data sources configured in the application server

For a Spring application to access a resource such as a JDBC data source, the application must use a resource provider that is managed by the application server.

To do this, see the Configure access to a Spring application data source topic.


JDBC native connections

WAS does not support the use of the NativeJdbcExtractor class that the Spring Framework provides, so avoid scenarios that use this class. Implementations of this class access native JDBC connections and bypass quality of service functions in the application server such as tracking and reassociating connection handles, sharing connections, managing connection pools and involvement in transactions.

As an alternative, you can use the application server WSCallHelper class to access non-standard vendor extensions for data sources.


Java Persistence API

WAS includes a default JPA provider based on the Apache OpenJPA implementation of JPA. See the related links.

To use the Spring Framework with a JPA implementation, it is advisable to use JPA directly rather than using the JPA helper classes that are provided with the Spring Framework in the org.springframework.orm.jpa package.

To use managed JPA from the Spring Framework, you define a persistence context reference in the web descriptor (web.xml):

<persistence-context-ref>
<persistence-context-ref-name>some/name
</persistence-context-ref-name>
<persistence-unit-name>pu_name
</persistence-unit-name>
</persistence-context-ref> 
where pu_name is the name of the persistence unit as defined in the persistence.xml file.

The persistence context is then available from JNDI through java:comp/env/some/name inside the web application. For the Spring Framework, the persistence context can then be retrieved using a <jee:jndi-lookup/> as shown in the following example code. The resulting EntityManager object is available under the "entityManager" ID.

<jee:jndi-lookup id="entityManager" jndi-name="some/name" /> 

Similarly, a persistence unit (for direct use, or use with Spring wrapper classes) can be made available through a persistence unit reference:

<persistence-unit-ref>
<persistence-unit-ref-name>some/ref_name
</persistence-unit-ref-name>
<persistence-unit-name>pu_name
</persistence-unit-name>
</persistence-unit-ref> 
The resulting EntityManagerFactory object is available under the "entityManagerFactory" ID:
<jee:jndi-lookup id="entityManagerFactory" jndi-name="some/ref_name" /> 

Additional Application Programming Interfaces (APIs)
Spring Framework
Configure access to a Spring application data source
Develop applications that use JNDI
Assembling data access applications
Develop JPA 2.x applications for a Java EE environment


Related


Data access portability features
Leveraging OpenJPA with WAS V6.1
Spring Documentation Concept topic

+

Search Tips   |   Advanced Search