2 replies Latest Post - ‏2011-10-01T12:28:10Z by logzyy
6 Posts

Pinned topic Help on deploying to websphere

‏2011-09-30T08:22:37Z |
Hi all,
I have created an app with neatbeans and deployed in glassfish i want to move it over to websphere 7. I am new to websphere but i have been able to install and set up my jdbc connection.I have a persistence.xml like this

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
<persistence-unit name="BACPOnline5PU" transaction-type="JTA">

I also have a persistence class with a method like this:

private PersistenceService() {
try {
this.em = (EntityManager) new InitialContext().lookup("java:comp/env/persistence/" + DEFAULT_PU);
this.utx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
} catch (NamingException ex) {
throw new RuntimeException(ex);

Can anyone hint me as to how to set this up on websphere to make it work?
How do i set up my Target Resource JNDI Name?
Thanks in anticipation
Updated on 2011-10-01T12:28:10Z at 2011-10-01T12:28:10Z by logzyy
  • sutter
    94 Posts

    Re: Help on deploying to websphere

    ‏2011-09-30T13:54:04Z  in response to logzyy
    A couple of items jump out at me. The first one is the <jta-data-source> identifier. Normally, this name would be qualified. If you are using direct JNDI lookups, then I would have expected something like:


    WebSphere also supports the use of a local, componentized name for the <jta-data-source>. This is very useful if you want to change the definition of the datasource to use, without changing the configuration of the application. This is also known as an indirect JNDI lookup (very similar to your indirect lookup of the persistence unit):


    Using this approach requires you to map this indirect resource reference to a physical datasource. I would focus on the use of direct JNDI lookups first until you get more comfortable with the WebSphere environment.

    Concerning your lookup of the persistence unit... Although JNDI will work, I'm curious why you wouldn't use annotation support and just annotate your EntityManager like this:

    EntityManager em;

    I don't personally use the JNDI approach for the EMF/EM, but it's my understanding that you would first need to reference the PU(EMF) before attempting to create the EM. Something like this:

    public class MySessionBean implements MyInterface {
    public void doSomething() {
    EntityManager em = (EntityManager)ctx.lookup("BACPOnline5PU");

    Are you indicating that this application as documented here works as-is in Glassfish?

    Hope this helps,
    Kevin Sutter, JPA Architect, IBM WebSphere
    • logzyy
      6 Posts

      Re: Help on deploying to websphere

      ‏2011-10-01T12:28:10Z  in response to sutter
      Hi Kevin Sutter,

      Thanks for your response, it's really appreciated. Yes, this application as documented works perfectly in Glassfish. I am about to start the deployment. i have attached my PersistenceService class for you to advise fully on the best way to go.
      Enifeni Ololade