views:

613

answers:

1

Disclaimer: I'm completely new to JEE/EJB and all that, so bear with me.

I have a simple EJB that I can successfully deploy using JDeveloper 11g's integrated WebLogic server and a remote database connection (JDBC). I have a DataSource named "PGY2" defined in WebLogic, and I can test it successfully from the admin console.

Here's the code of the client I'm trying to test it with (generated entirely by JDev except for the three method calls on adminManager):

public class AdminManagerClient {
    public static void main(String [] args) {
        try {
            final Context context = getInitialContext();
            AdminManager adminManager = (AdminManager)context.lookup("Uran-AdminManager#hu.elte.pgy2.BACNAAI.UranEJB.AdminManager");
            adminManager.addAdmin("root", "root", "Kovács Isten");
            adminManager.addStudent("BACNAAI", "matt", "B Cs", 2005);
            adminManager.addTeacher("SIPKABT", "patt", "S P", "numanal", "Dr.");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private static Context getInitialContext() throws NamingException {
        Hashtable env = new Hashtable();
        // WebLogic Server 10.x connection details
        env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
        env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7101");
        return new InitialContext( env );
    }
}

But when I try to run this, I get the following error on the line with adminManager.addAdmin (that is, after the lookup):

javax.ejb.EJBException: EJB Exception: ; nested exception is: 
    Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.2 (Build 20081024)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Internal error: Cannot obtain XAConnection Creation of XAConnection for pool PGY2 failed after waitSecs:30 : java.sql.SQLException: Data Source PGY2 does not exist.

Why can't the client find the data source, and how do I make it find it?


EDIT: I took a closer look at WebLogic's output during deployment, and I found this. I have no idea what it means, but it may be relevant:

<2010.05.20. 0:50:43 CEST> <Error> <Deployer> <BEA-149231> <Unable to set the activation state to true for the application 'PGY2'.
weblogic.application.ModuleException: 
    at weblogic.jdbc.module.JDBCModule.activate(JDBCModule.java:349)
    at weblogic.application.internal.flow.ModuleListenerInvoker.activate(ModuleListenerInvoker.java:107)
    at weblogic.application.internal.flow.DeploymentCallbackFlow$2.next(DeploymentCallbackFlow.java:411)
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
    at weblogic.application.internal.flow.DeploymentCallbackFlow.activate(DeploymentCallbackFlow.java:74)
    Truncated. see log file for complete stacktrace
weblogic.common.ResourceException:  is already bound
    at weblogic.jdbc.common.internal.RmiDataSource.start(RmiDataSource.java:387)
    at weblogic.jdbc.common.internal.DataSourceManager.createAndStartDataSource(DataSourceManager.java:136)
    at weblogic.jdbc.common.internal.DataSourceManager.createAndStartDataSource(DataSourceManager.java:97)
    at weblogic.jdbc.module.JDBCModule.activate(JDBCModule.java:346)
    at weblogic.application.internal.flow.ModuleListenerInvoker.activate(ModuleListenerInvoker.java:107)
    Truncated. see log file for complete stacktrace
> 
+1  A: 

Actually, it's not the EJB client that can't find the DataSource, it's the code running inside the container and using JPA. More precisely, it's the JPA provider - EclipseLink here - that can't find it. Double check that the datasource name defined in your persistence.xml (in the <jta-data-source>) matches the JNDI name of the PGY2 DataSource.

WebLogic provides a JNDI browser (to browse the JNDI tree), use it if required to see under which name your datasource is registrered.

Update: Could you have linebreaks in the JNDI name field of the datasource (see this blog post)?

Pascal Thivent
In the DataSource's configuration, JNDI Name is set as "PGY2", which seems to be correct (WebLogic starts infinitely generating `StackOverflowError` s when I try to view the JNDI tree, but the server's Services tab shows the DataSource with that JNDI name). "PGY2" is also the name set in `persistence.xml`. Indeed, if I change either one, I get a `PersistenceUnitInfo Model has transactionType JTA, but doesnt have jtaDataSource` error when trying to deploy, which I'm led to understand means that the DataSource couldn't be contacted.
suszterpatt
@suszterpatt Indeed, this was a good test.
Pascal Thivent
Yep, that's it. Line breaks in the JNDI Name field. Deleted them, and now the client is complaining about the SQL queries I'm trying to execute, so apparently all is well on the DB connection front. Thanks a lot!
suszterpatt