Topic
  • 2 replies
  • Latest Post - ‏2011-10-01T12:28:10Z by logzyy
logzyy
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="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="BACPOnline5PU" transaction-type="JTA">
<jta-data-source>infopool</jta-data-source>
<properties/>
</persistence-unit>
</persistence>

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
    sutter
    94 Posts

    Re: Help on deploying to websphere

    ‏2011-09-30T13:54:04Z  
    Hi,
    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:

    <jta-data-source>jdbc/infopool</jta-data-source>

    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):

    <jta-data-source>java:comp/env/jdbc/infopool</jta-data-source>

    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:

    @PersistenceContext(unitName="BACPOnline5PU")
    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:

    @Stateless
    @PersistenceContext(name="BACPOnline5PU")
    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
    logzyy
    6 Posts

    Re: Help on deploying to websphere

    ‏2011-10-01T12:28:10Z  
    • sutter
    • ‏2011-09-30T13:54:04Z
    Hi,
    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:

    <jta-data-source>jdbc/infopool</jta-data-source>

    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):

    <jta-data-source>java:comp/env/jdbc/infopool</jta-data-source>

    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:

    @PersistenceContext(unitName="BACPOnline5PU")
    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:

    @Stateless
    @PersistenceContext(name="BACPOnline5PU")
    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
    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.
    Thanks
    Enifeni Ololade