简体   繁体   中英

Setting datasource JNDI in embeddable WebSphere EJB container

I am using the embeddable EJB container of WebSphere 8 to write some unit tests for my EJBs with JUnit4. I have a simple java project in MyEclipse where I reference the EJB project. The EJB project uses Hibernate 3.5 for persistence and the datasource JNDI in hibernate.cfg.xml is jdbc/connectionname. When it runs on standard WebSphere 8 I have set up the datasource through the web console and all works fine. On the embeddable container the datasource is set up in embeddable.properties with:

name again as jdbc/connectionname among other datasource info (username, password etc.) and Bean.#TestProjectName#ClassNameForTests.ResourceRef.BindingName.jdbc/connectionname=jdbc/connectionname

My embeddable.properties is as follows:

DataSource.ds1.name=jdbc/connectionname
DataSource.ds1.className=com.ibm.db2.jcc.DB2Driver
DataSource.ds1.createDatabase=create
DataSource.ds1.databaseName=DBNAME
DataSource.ds1.user=dbusername
DataSource.ds1.password=dbpassword
DataSource.ds1.transactional=true
DataSource.ds1.createDatabase=create

The embeddable container starts successfully and the EJBs can be found successfully through JNDI but at the point where the method call is made I get the error:

ERROR org.hibernate.connection.DatasourceConnectionProvider.configure:78 - Could not find datasource: jdbc/connectionname
javax.naming.NameNotFoundException: Name jdbc not found in context "serverlocal:CELLROOT/SERVERROOT".
at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1969)
at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1376)
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1219)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1141)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1314)
at javax.naming.InitialContext.lookup(InitialContext.java:436)
at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)

Any advice would be appreciated.

Is the jdbc/connectionname data source configured via embeddable properties? See the Embeddable EJB container configuration properties InfoCenter topic. You properties should look something like this:

DataSource.ds1.name=jdbc/connectionname
DataSource.ds1.className=org.apache.derby.jdbc.EmbeddedXADataSource
DataSource.ds1.createDatabase=create
DataSource.ds1.databaseName=jtest1

If you already have this, can you show the properties you're using? Note that Hibernate is not using your resource reference, so the ResourceRef.BindingName has no effect in this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM