WAS v8.5 > WebSphere applications > Spring applications > Spring Framework

Data access and the Spring Framework

For Spring beans to access a data source, configure those beans so the Spring Framework delegates to, and integrates with, the WebSphere Application Server 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 we 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 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, we 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. For more information, 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 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):

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.

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

The resulting EntityManagerFactory object is available under the "entityManagerFactory" ID:


Related concepts:

Additional Application Programming Interfaces (APIs)


Related


Configure access to a Spring application data source
Develop applications that use JNDI
Assemble data access applications
Develop JPA 2.x applications for a Java EE environment


Reference:

Data access portability features


Related information:

Leveraging OpenJPA with WAS V6.1

Spring Documentation


+

Search Tips   |   Advanced Search