Discussion:
[jboss-user] [Datasource Configuration] - Need help accessing a jdbc datasource inside ejb on jboss 7.1.1
tareq zaman
2013-07-03 00:40:33 UTC
Permalink
tareq zaman [https://community.jboss.org/people/tareq_zaman] created the discussion

"Need help accessing a jdbc datasource inside ejb on jboss 7.1.1"

To view the discussion, visit: https://community.jboss.org/message/826053#826053

--------------------------------------------------------------
Hi,


I would appreciate any help on this. I have tried so many ways but no success yet. I am trying to test a datasource inside an session ejb in JBoss AS 7.1.1.Final. Using MS SQL server.




Getting name not found exception, here is the stack trace. Please note in the code I am using the full JNDI name as java:jboss/datasources/ezsystemDS.


19:20:57,293 ERROR [stderr] (EJB default - 1) javax.naming.NameNotFoundException: jboss/datasources/ezsystemDS -- service jboss.naming.context.java.jboss.exported.jboss.datasources.ezsystemDS


19:20:57,306 ERROR [stderr] (EJB default - 1)           at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)


19:20:57,317 ERROR [stderr] (EJB default - 1)           at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)


19:20:57,325 ERROR [stderr] (EJB default - 1)           at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)


19:20:57,332 ERROR [stderr] (EJB default - 1)           at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)


19:20:57,337 ERROR [stderr] (EJB default - 1)           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)


19:20:57,341 ERROR [stderr] (EJB default - 1)           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)


19:20:57,344 ERROR [stderr] (EJB default - 1)           at java.lang.Thread.run(Thread.java:724)


19:20:57,646 INFO  [org.jboss.as.naming] (Remoting "sc1-mis99" task-3) JBAS011806: Channel end notification received, closing channel Channel ID 5643bfb0 (inbound) of Remoting connection 0148380c to null




When Jboss starts I can see datasources are bound correctly. Also verified that from JBOSS console naming tree view.


[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-14) JBAS010400: Bound data source [java:jboss/datasources/ezsystemSeqDS]
19:15:45,643 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]
19:15:45,643 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-11) JBAS010400: Bound data source [java:jboss/datasources/ezsystemDS]
19:15:45,947 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990 http://127.0.0.1:9990
19:15:45,948 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss AS 7.1.1.Final




Here is my ejb code




           public String echo(String input){
                        try {
                                        InitialContext ctx = new InitialContext();
                                        DataSource datasrc =  (DataSource)ctx.lookup("java:jboss/datasources/ezsystemDS");
                                        if(datasrc != null) {
                                                  Connection con = datasrc.getConnection();
                                                  con.close();
                                        }

                              } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        String x = e.getMessage();
                                        e.printStackTrace();
                              }
                        return "Echoing back " + input ;
    }



Data sources are configured in module.xml and created using admin console. Thanks.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/826053#826053]

Start a new discussion in Datasource Configuration at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]
Wolf-Dieter Fink
2013-07-03 06:12:39 UTC
Permalink
Wolf-Dieter Fink [https://community.jboss.org/people/wdfink] created the discussion

"Re: Need help accessing a jdbc datasource inside ejb on jboss 7.1.1"

To view the discussion, visit: https://community.jboss.org/message/826072#826072

--------------------------------------------------------------
What application is it. If you use ejb3 it might be easier to use injection with +@Resource+ to get a DS reference
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/826072#826072]

Start a new discussion in Datasource Configuration at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]
tareq zaman
2013-07-03 14:17:24 UTC
Permalink
tareq zaman [https://community.jboss.org/people/tareq_zaman] created the discussion

"Re: Need help accessing a jdbc datasource inside ejb on jboss 7.1.1"

To view the discussion, visit: https://community.jboss.org/message/826197#826197

--------------------------------------------------------------
https://community.jboss.org/people/wdfink Wolf-Dieter Fink,

Thanks. This is a ejb 3 app. I have tested with @Resource injection and DS reference working fine. My problem is I will be using Toplink native API to make database changes (No JPA). Toplink configuration is loaded from a sessions.xml file with a DS JNDI reference. Internally Toplink doing a context.lookup by datasource name. It was failing because of name not found exception. I was testing if JBOSS allows context.lookup by DS JNDI name.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/826197#826197]

Start a new discussion in Datasource Configuration at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]
Wolf-Dieter Fink
2013-07-03 18:03:46 UTC
Permalink
Wolf-Dieter Fink [https://community.jboss.org/people/wdfink] created the discussion

"Re: Need help accessing a jdbc datasource inside ejb on jboss 7.1.1"

To view the discussion, visit: https://community.jboss.org/message/826241#826241

--------------------------------------------------------------
I'm not sure, but this might be related to the ClassLoader as you are not inside of a EJB or even the application context (I suppose you use a module fro that)
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/826241#826241]

Start a new discussion in Datasource Configuration at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]
tareq zaman
2013-07-03 18:44:14 UTC
Permalink
tareq zaman [https://community.jboss.org/people/tareq_zaman] created the discussion

"Re: Need help accessing a jdbc datasource inside ejb on jboss 7.1.1"

To view the discussion, visit: https://community.jboss.org/message/826250#826250

--------------------------------------------------------------
Doing the context lookup inside the ejb.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/826250#826250]

Start a new discussion in Datasource Configuration at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2077]
Loading...