Identify and modify the JPA specification level
Newly created profiles default to the Java Persistence API (JPA) 2.1 specification. We can run AdminTask wsadmin commands to list JPA specifications supported by the product and to change the JPA specification used by a server, server cluster, or servers that are members of a cluster.
In the Java EE Application Client environment, only the JPA 2.1 specification, using the EclipseLink bundle provided by WebSphere Application Server, is supported..
New feature:
newfeat
WAS version 9 supports both the JPA 2.1 and JPA 2.0 specification levels. JPA 2.1 simplifies the management of relational data in applications. We can find information about supported JPA specification levels and JPA providers using the wsadmin tool or the administrative console. Run the wsadmin AdminTasklistSupportedJPASpecifications command to list JPA specification levels and default JPA providers supported by the product. Run the AdminTask showJPASpecLevel command to identify the JPA specification level used by a cluster or server. Run the AdminTask modifyJPASpecLevel command to change the JPA specification level used by a cluster or server.
Starting with WAS v9, Eclipselink is provided as a JPA 2.1 provider implementation and is the default persistence provider when JPA 2.1 is configured to be the active specification level. Before version 9, WSJPA, the IBM JPA provider based on Apache OpenJPA, which supports the JPA 2.0 specification, was the default JPA persistence provider. Because JPA providers differ in both behavior and vendor-specific APIs, and OpenJPA is not available as a JPA 2.1 specification implementation, WAS v9 provides a JPA 2.0 specification compatibility mode.
The product bundles the following JPA persistence providers:
- Eclipselink 2.6.x_WAS (default for the JPA 2.1 specification)
- WSJPA 2.2.x (default for the JPA 2.0 specification)
Use third-party JPA providers as mandated by the JPA specification. The third-party JPA provider implementation must match the enabled JPA specification level.
Tasks
- List JPA specification levels supported by the product.
WAS version 9 supports both JPA 2.1 and JPA 2.0 specification levels.
- Start the wsadmin tool.
- Identify the JPA specification levels supported by the current WAS installation.
wsadmin>print AdminTask.listSupportedJPASpecifications()
Supported JPA Specification levels are:
Spec Level Default JPA Provider Version
2.0 OpenJPA 2.2.x
2.1 Eclipselink 2.6.x_WASTo list only the supported JPA specification level values, use the -versionOnly parameter with a value of true:
wsadmin>print AdminTask.listSupportedJPASpecifications('[-versionOnly]')
2.0
2.1
- Identify the current JPA specification level as configured on a cluster or server.
The JPA specification level for the target cluster or server can be identified using the wsadmin scripting tool or the administrative console
- Start the wsadmin tool.
- Run the AdminTask showJPASpecLevel command. The showJPASpecLevel command can take either the node and server name as parameters or it can take an object name that references a cluster or server configuration object.
Example 1: Targeting a stand-alone server using node and server parameters
wsadmin>AdminTask.showJPASpecLevel('[-node myNode -server server1]')
2.1Example 2: Targeting a standalone server using an object name
wsadmin>svr = AdminConfig.getid('/Server:server1/')
myCell/nodes/myNode/server/server1|server.xml#Server_1183122130078)
wsadmin>AdminTask.showJPASpecLevel(svr)
2.1Example 3: Targeting a server cluster using an object name
wsadmin>svrClstr = AdminConfig.getid('/ServerCluster:AcmeCluster')
wsadmin>AdminConfig.show(svrClstr, "name") '[name AcmeCluster]'
wsadmin>AdminTask.showJPASpecLevel(svrClstr)
'2.1'Example 4: Targeting a server cluster using a cluster's server member:
wsadmin>svr1 = AdminConfig.getid("/Node:node1/Server:member_node1/")
wsadmin>AdminConfig.show(svr1, "[name clusterName]") '[clusterName AcmeCluster] [name member_node1]'
wsadmin>AdminTask.showJPASpecLevel(svr1)
'2.1'
- Modify the selected JPA specification level for a server JPA specification level for the target Server can be changed using the wsadmin tool or the administrative console.
- Start the wsadmin tool.
- Run the modifyJPASpecLevel command. The AdminTask modifyJPASpecLevel command can take either the node and server name as parameters or it can take an object name that references a server or server cluster configuration object. If a server is part of a server cluster, the node and server parameters can be used to address the cluster, affecting all member servers associated with the cluster. An additional specLevel parameter is required and accepts values equal to those that are produced by the listSupportedJPASpecifications command.
Example 1: Targeting a stand-alone server using node and server parameters
wsadmin>AdminTask.modifyJPASpecLevel('[-node myNode -server server1 -specLevel 2.0]')
CWWJP8813I: The JPA specification compliance level for Server server1 has been successfully set to JPA 2.0.Example 2: Targeting a stand-alone server using an object name
wsadmin>svr = AdminConfig.getid('/Server:server1/')
server1(cells/myCell/nodes/myNode/server/server1|server.xml#Server_1183122130078
wsadmin>AdminTask.modifyJPASpecLevel(svr, '[ -specLevel 2.0]')
CWWJP8813I: The JPA specification compliance level for Server server1 has been successfully set to JPA 2.0.Example 3: Targeting a server cluster using an object name
# svrCluster is a reference to ServerCluster object "AcmeCluster"
# svr1 is a reference to Server "node1:member_node1", a member of "AcmeCluster"
# svr2 is a reference to Server "node1:member_node1", a member of "AcmeCluster"
wsadmin>AdminTask.showJPASpecLevel(svrClstr)
'2.1'
wsadmin>AdminTask.showJPASpecLevel(svr1)
'2.1'
wsadmin>AdminTask.modifyJPASpecLevel(svrClstr, '[ -specLevel 2.0]')
'CWWJP8813I: The JPA specification compliance level for Cluster AcmeCluster has been successfully set to JPA 2.0.'
wsadmin>AdminTask.showJPASpecLevel(svrClstr)
'2.0'
wsadmin>AdminTask.showJPASpecLevel(svr1)
'2.0'
wsadmin>AdminTask.showJPASpecLevel(svr2)
'2.0'Example 4: Targeting a server cluster using a cluster's server member
# svrCluster is a reference to ServerCluster object "AcmeCluster"
# svr1 is a reference to Server "node1:member_node1", a member of "AcmeCluster"
# svr2 is a reference to Server "node1:member_node1", a member of "AcmeCluster"
wsadmin>AdminTask.showJPASpecLevel(svrClstr)
'2.1'
wsadmin>AdminTask.showJPASpecLevel(svr1)
'2.1'
wsadmin>AdminTask.showJPASpecLevel(svr2)
'2.1'
wsadmin>AdminTask.modifyJPASpecLevel(svr1, '[ -specLevel 2.0]')
'CWWJP8813I: The JPA specification compliance level for Cluster AcmeCluster has been successfully set to JPA 2.0.'
wsadmin>AdminTask.showJPASpecLevel(svrClstr)
'2.0'
wsadmin>AdminTask.showJPASpecLevel(svr1)
'2.0'
wsadmin>AdminTask.showJPASpecLevel(svr2) '2.0'The modifyJPASpecLevel command does not alter the JPA persistence provider implementation configuration. If we have a JPA persistence provider implementation configured and we start the modifyJPASpecLevel command, we will see an informational message that recommends that you verify the JPA persistence provider implementation is valid for the JPA specification level:
wsadmin>AdminConfig.create("JavaPersistenceAPIService", svr1,
[['defaultPersistenceProvider',
com.acme.jpa.MyJPA21PersistenceProviderImpl']])
wsadmin>AdminTask.modifyJPASpecLevel(svr1, '[ -specLevel 2.0]')
'CWWJP8816I: The JPA specification compliance level for Cluster AcmeCluster has been successfully set to JPA 2.0. Verify that the configured default JPA
Persistence Provider, com.acme.jpa.MyJPA21PersistenceProviderImpl, is valid for this JPA specification level.'- Save the configuration.
- Restart the server for the JPA specification change to take effect.