Lookup jndi resources WebSphere 8.5, Spring 3.1.3, Hibernate 4.1.10 EJB 3 - spring

In my application I need to lookup jndi resources for database connection.
I have an EAR which contain my EJB project with remote and stateless ejb: ABean.jar
Reading Using Spring and Hibernate with WebSphere Application Server I defined
in the application.xml of EAR project:
<module>
<ejb>ABean.jar</ejb>
</module>
<resource-ref>
<res-ref-name>jdbc/b</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
In my spring context:
<jee:jndi-lookup
id="aDataSource"
jndi-name="jdbc/b"
cache="true"
expected-type="javax.sql.DataSource"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="META-INF/persistence.xml"/>
<property name="dataSource" ref="aDataSource" />
<property name="persistenceUnitName" value="APU"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.DB2390Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="jpaDialect">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
</property>
</bean>
Now, if I install application by WebSphere console, it ask to me to assign the jndi resource to jdbc/b (and it is ok), but if I try to call an ejb, a NameNotFoundException is throw because jdbc/b is not found!
Reading better the previous link i see:
For EJB JAR files, the same resource-ref should be declared in each EJB that needs to access the data source.
so I try to define resource references into my ejb-jar.xml
<enterprise-beans>
<session>
<ejb-name>TestServiceBean</ejb-name>
<ejb-class>it.test.TestServiceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref>
<res-ref-name>jdbc/b</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
</resource-ref>
</session>
</enterprise-beans>
I try to install again (I also assign the jndi resource to jdbc/b) and the call to the ejb run successfully, but if I have n ejb, do I need to assign n-times the same jndi resource to the n ejb resource-ref for jdbc/b?
What is wrong with my configuration? Isn't it possible "point" to the same resource-ref from all ejb? Do you have a complete example?

Per the EE 6 spec, references declared in application.xml must be in the java:app (or java:global) namespaces, and it is recommend that they be in the env subcontext, so:
<res-ref-name>java:app/env/jdbc/b</res-ref-name>
This will allow the resource to be visible to all components in the application. Alternatively, you can declare a reference in the java:module context in ejb-jar.xml or via annotation.

Updated answer. Example based on bkail answer. You need to define resource reference in application.xml like this:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<display-name>RefTestEAR</display-name>
....
<resource-ref>
<res-ref-name>java:app/env/jdbc/b</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</application>
Then in your application you can access it via:
InitialContext ctx = new InitialContext();
DataSource datasource = (DataSource) ctx.lookup("java:app/env/jdbc/b");
In your case since you are using Spring not InitialContext directly, you will probably need to change the lookup to and also verify if you have datasource reference in persistence.xml (I didn't test that in Spring as I don't have Spring sample at hand):
<jee:jndi-lookup
id="aDataSource"
jndi-name="java:app/env/jdbc/b"
cache="true"
expected-type="javax.sql.DataSource"/>

Related

How to use properties from OSGI/Karaf ConfigurationAdminService with Spring dependency injection

I am trying to inject properties stored in Karaf into my Camel/Spring-Service. So far i tried to inject the properties the way documented in Fuse documentation and Spring.
But both seem outdated: the osgix:cm-properties can't be parsed by current Spring version (Fuse 6.3 uses 3.2.16).
On the other hand Apache Aries seem to have something that could be used now. The aries-blueprint-spring feature contains two bundles:
aries.blueprint.spring
aries.blueprint.spring.extender
I found an old user-list post that points to this bundles. But i can't find any documentation or example using this. We only need to inject the properties.
Have been using OSGi Service Compendium for sometime now and below is some extract from one of my projects, hope it helps.
Important is the declaration of compendium namespace and it's prefix osgix
Also note the declaration of persistent-id as the same has to be defined in Karaf configuration file to be created inside etc directory of your container instance.
Now there is Spring property-placeholder referring to osgix properties declaration and propertyPlaceholder inside CamelContext. Both are required if you want to access properties outside - ${propName} and inside - {{propName}} CamelContext.
To access properties outside Camel Context syntax is ${propertyName}
To access properties inside Camel Context syntnax is {{propertyName}}
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" xmlns:ctx="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- A. Configuration Management -->
<osgix:cm-properties id="cachingServicesProp" persistent-id="com.fsafrica.cachingservices.cm">
<prop key="amqBrokerUrl">tcp://localhost:61616</prop>
<prop key="amqUsername">admin</prop>
<prop key="amqPassword">admin</prop>
<prop key="queueName">jms/SRK_CACHE_QUEUE</prop>
</osgix:cm-properties>
<!-- Required for resolving properties for Beans outside CamelContext -->
<ctx:property-placeholder properties-ref="cachingServicesProp" />
<!-- B. ActiveMQ -->
<bean class="org.apache.activemq.camel.component.ActiveMQComponent" id="activemq">
<property name="brokerURL" value="${amqBrokerUrl}" />
<property name="userName" value="${amqUsername}" />
<property name="password" value="${amqPassword}" />
</bean>
<camelContext id="CC-CachingMain" xmlns="http://camel.apache.org/schema/spring">
<!-- Required for resolving properties inside CamelContext -->
<propertyPlaceholder id="properties" location="ref:cachingServicesProp"/>
<!-- JMS INTERFACE -->
<route id="Route-JMSMasterData">
<from uri="activemq:queue:{{queueName}}?transacted=false" />
<log message="#### After putting some data in the Queue (jms/SRK_CACHE_QUEUE) you should be able read this text on Karaf console" />
</route>
</camelContext>
</beans>

Transaction is not committed when using local/global JNDI datasource lookup in a spring/eclipselink project in weblogic

When I use the global JNDI name in the persistence.xml, everything works ok.
It goes wrong when I use a local JNDI name, add the resource-ref to the web.xml and map the local name to the global name in the weblogic.xml. He deploys successfully, finds the datasource, does selects and inserts, but never commits! The commit does happen when I use the global JNDI name directly in the persistence.xml.
My spring context is as follows:
<bean id="localContainerEntityManagerFactoryBean" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="rctUnit" />
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager" />
<tx:annotation-driven transaction-manager="transactionManager" />
The persistence.xml after the change:
<persistence-unit name="rctUnit" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:comp/env/jdbc/rct</jta-data-source>
And the following added to the web.xml and the weblogic.xml:
<resource-ref>
<description>RCT DB</description>
<res-ref-name>jdbc/rct</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-description>
<res-ref-name>jdbc/rct</res-ref-name>
<jndi-name>db.datasource.rct</jndi-name>
</resource-description>
Following versions are used:
eclipselink: 2.0.2
jpa: 1.0.0
spring: 3.2.0.RELEASE
weblogic: 10.3.3
I was able to solve it by adding an eclipseLink property to the persistence.xml:
<property name="eclipselink.target-server" value="weblogic" />
I don't have any clue why this property is not needed when the global JNDI name is used in the persistence.xml. The eclipse property is not needed then to make it work. When using the local JNDI name in the persistence.xml, this property is needed to make the transaction commits.
Probably because the prefix java:comp/ is different according to deployment environment, some may not use the "comp" part

Migrating JAX-WS RI to Spring controlled service without SOAP?

Excuse me if I use incorrect terminology, I'm a bit new to this. I've created a web service using Sun's JAX-WS RI "Provider" implementation. We send this service plain XML, and it responds in plain XML. I've tried to move this into Spring so the services are accessible via Spring context, but now it's looking for a SOAP envelope, which we are not using. How do I tell it I am not using SOAP?
My web.xml looks like this:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<display-name>MyServiceImpl</display-name>
<servlet-name>MyServiceImpl</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyServiceImpl</servlet-name>
<url-pattern>/myServiceUrl</url-pattern>
</servlet-mapping>
And here's my applicationContext.xml:
<!-- this bean implements web service methods -->
<bean id="myService" class="com.acme.MyServiceImpl" />
<bean class="com.sun.xml.ws.transport.http.servlet.SpringBinding">
<property name="url" value="/myServiceUrl" />
<property name="service">
<bean class="org.jvnet.jax_ws_commons.spring.SpringService">
<property name="bean">
<ref local="myService" />
</property>
<property name="impl" value="com.acme.MyServiceImpl" />
</bean>
</property>
</bean>
My service class looks something like this:
#javax.xml.ws.WebServiceProvider
#javax.xml.ws.ServiceMode(value=javax.xml.ws.Service.Mode.MESSAGE)
public class MyServiceImpl implements Provider<Source> {
#Override
public Source invoke(Source source) {
... // unmarshal the source object using JAXB, do work, marshall a response back
}
The error message I receive upon sending the service my basic XML is:
<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"><faultcode>S:Client</faultcode><faultstring>Couldn't create SOAP message due to exception: unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {}Request</faultstring></S:Fault></S:Body></S:Envelope>
How do I rid the SOAP?
Found it; need to specify the bindingId (which was defined in the sun-jaxws.xml previously) on the web service bean:
<property name="service">
<bean class="org.jvnet.jax_ws_commons.spring.SpringService">
<property name="bean">
<ref local="myService" />
</property>
<property name="impl" value="com.acme.MyServiceImpl" />
<property name="bindingID" value="http://www.w3.org/2004/08/wsdl/http" />
</bean>
</property>

Why do I get an unexpected EntityManagerFactory when using JPA within WebLogic?

I am trying to create a Spring MVC web app (Spring Framework 3.0.5). I am using IntelliJ IDEA 11.1.3 to deploy my app on a WebLogic Server (10.3.4). One of my web pages attempts to store some data in a database using JPA. My persistence.xml specifies:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="LeaveSchedulerJPA" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.engilitycorp.leavetracker.jpa.UserRole</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:#localhost:1521:xe "/>
<property name="javax.persistence.jdbc.user" value="leavescheduler"/>
<property name="javax.persistence.jdbc.password" value="xxx"/>
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
</properties>
</persistence-unit>
</persistence>
However, when I look in the debugger, my EntityManagerFactory is shown as an org.apache.openjpa.persistence.EntityManagerFactoryImpl, and when I call createEntityManager, I get an org.apache.openjpa.persistenceArgumentException that states that "A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property".
It appears to my newbie eye that the persistence.xml may not be getting processed. I've tried putting it in (project)/src/main/resources/META-INF and (project)/src/main/resources/META-INF/spring, with the same unfortunate result.
I am not committed to using Hibernate persistence; however, I do want to use something that implements JPA 2, and I am having a real hard time configuring my environment. For example, I have little idea how openjpa got involved in my app. I suppose it may be the default JPA provider for something (WebLogic?, IntelliJ IDEA?). Any help/suggestions would be much appreciated.
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
root-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
</beans>
servlet-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.engilitycorp.leavetracker" />
</beans:beans>
WebLogic 10.3.4 is Java EE 5 compliant and is shipped with JPA 1.0 implementations: OpenJPA and TopLink.
According to WebLogic documentation ( http://docs.oracle.com/cd/E17904_01/web.1111/e13720/using_toplink.htm#CIHDJHHI ) it can be used also with JPA 2.0 but only after applying a patch. Simply follow the instructions (patching seems to be quite simple but I didn't test it).
Probably you can also use your own JPA 2.0 provider without patching, as user1654209 wrote in first answer. But JPA 1.0 classes supplied with WebLogic can get in the way, because they are loaded by higher level classloader and have priority over classes packaged in your WAR file. To prevent such behaviour you have two options:
pack your application's WAR within an EAR archive with META-INF/weblogic-application.xml file containing following lines (you must also include standard META-INF/application.xml file):
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application/1.0/weblogic-application.xsd">
<prefer-application-packages>
<package-name>javax.persistence.*</package-name>
</prefer-application-packages>
</weblogic-application>
add WEB-INF/weblogic.xml file to your WAR archive with following lines:
<?xml version='1.0' encoding='UTF-8'?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
</weblogic-web-app>
You need to configure an entityManagerFactory bean in your context.xml. Heres is an exemple using eclipselink as the JPA provider
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
id="dataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
</bean>
<bean
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean id="jpaAdapter"
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
</bean>
</property>
</bean>
Just setting the provider isn't enough. You need to set the database connection data, like jdbc url, username and password. Did you set it? You also need to set the jdbc class name, as said, and the jdbc driver needs to be in your classpath.
If you are running this on a container and want to configure the datasource in weblogic, you can just refer to a jndi datasource from your hibernate cfg, but you will need to enter in the weblogic console and create a datasource and a connection pool there.
Look at hibernate docs on how to set the JNDI name in persistence.xml

Spring DB2 JPA Entity Manager Problem

I'm trying to configure Spring, JPA and DB2 in order to have the entity manager instance to be used in my spring controllers but according how I have configured Spring this not happens.
These are the two attempts of configuration of spring:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource" />
<bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="em" />
</bean>
<bean id="em"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="fileUtility" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
<property name="database" value="DB2" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
the second is this:
<!-- Entity manager factory bean. -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="Sample" />
</bean>
<!-- Entity manager bean. -->
<bean id="em" factory-bean="entityManagerFactory"
factory-method="createEntityManager" />
and the entity manager is injected in this way:
<bean id="messageService" class="utilities.services.impl.MessageServiceImpl">
<property name="entityManager" ref="em" />
</bean>
but I have always this exception:
Caused by: java.lang.IllegalArgumentException: methods with same signature createEntityManager() but incompatible return types: [interface com.ibm.websphere.persistence.WsJpaEntityManager, interface org.apache.openjpa.persistence.OpenJPAEntityManagerSPI]
I don't know how can be fixed. Has anyone encountered this problem?
Thanks in advance.
[EDIT]
This is my persistence.xml:
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name="fileUtility"
transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<mapping-file>META-INF/mapping.xml</mapping-file>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:db2://localhost:50000/db2admin" />
<property name="openjpa.ConnectionDriverName" value="COM.ibm.db2.jdbc.app.DB2Driver" />
<property name="openjpa.ConnectionUserName" value="db2admin" />
<property name="openjpa.ConnectionPassword" value="XXXX" />
<property name="openjpa.FlushBeforeQueries" value="true"/>
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
</properties>
</persistence-unit>
<persistence-unit name="fileUtility2" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>file_ds</jta-data-source>
<mapping-file>META-INF/mapping.xml</mapping-file>
<properties>
<property name="openjpa.Log" value="SQL=TRACE"/>
<property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72"/>
</properties>
</persistence-unit>
</persistence>
WebSphere has a JPA implementation bundled. So no need to add openjpa to your lib. In fact, WebSphere is using OpenJPA, so you are not losing anything. Look here for more details
When using a jda-data-source, you need to have transaction-type="JTA". Also, you should not specify connection properties - they are specified in the datasource.
And get rid of the <provider> - the document I linked says:
If no JPA provider is configured in the element of the persistence.xml file within an EJB module, the default JPA provider that is currently configured for this server is used
I believe you're doing the wrong configuration, because you're configuring it "à la Tomcat". If you're using a Java EE application server, such as WAS, you should:
In Spring application context xml file
configure the DAO bean by a <bean> definition
configure the JNDI definition for the datasource created in the application server via a
<jee:jndi-lookup>
definition; the
name
attribute should be
persistence/XXX, where XXX shall match the
<persistence-unit name="XXX" transaction-type="JTA">
in persistence.xml file
The id attribute in the
<jee:jndi-lookup id=YYY> should point to the
name=YYY parameter of the Entity Manager definition in the DAO, this is to say,
#PersistenceContext(name=YYY) EntityManager em;
Specify
<tx:annotation-driven /> and
<tx:jta-transaction-manager />
In file
web.xml of your web app you should include a definition using the xml tag
<persistence-unit-ref> whose
<persistence-unit-ref-name> parameter shall be the
persistence/XXX JNDI name as specified in persistence.xml (shown above).
Finally, you should create a JNDI definition in the application server (AS dependant) that defines the JNDI name for the JDBC connection. This name should match the
<jta-data-source> xml tag in the persistence.xml file, and it is the only link between the JPA definition and the JDBC defined in the application server.
To round up:
Application Context Spring file
<bean class="DAO implementation class" />
<jee:jndi-lookup id="YYY" jndi-name="persistence/XXX" />
<tx:annotation-driven />
<tx:jta-transaction-manager />
persistence.xml file
<persistence-unit name="XXX" transaction-type="JTA">
<jta-data-source>jdbc/DSN</jta-data-source>
</persistence-unit>
web.xml file
...
<persistence-unit-ref>
<persistence-unit-ref-name>persistence/XXX</persistence-unit-ref-name>
</persistence-unit-ref>
...
DAO (only #PersistenceContext shown)
...
#PersistenceContext(name = "YYY")
EntityManager em;
...
Application Server: jdbc/DSN links to the connection definition, where the driver for the DBM is. Depends on both the AS and the DBM used.
Thus, you may see the connection between the DAO -> Spring Application Context file -> persistence.xml and web.xml files -> Application Server JNDI names. IF you're using a full Java EE application server (such as WAS, Weblogic or GlassFish) you don't have to use Spring interface modules; only defnitions in the app server (see Spring documentation, section 12.6.3).

Resources