Data access and the Spring Framework
For Spring beans to access a data source, you must configure those beans so that 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 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 Java™ Database Connectivity (JDBC) data source, the application must use a resource provider that is managed by the application server.
To do this, see the Configuring access to a Spring application data source topic.
JDBC native connections
WebSphere Application Server 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
WebSphere Application Server 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 that are provided with the Spring Framework in the org.springframework.orm.jpa package.
<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.entityManagerID.
<jee:jndi-lookup id="entityManager" jndi-name="some/name" />
<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
entityManagerFactoryID:
<jee:jndi-lookup id="entityManagerFactory" jndi-name="some/ref_name" />