[jboss-user] [EJB 3.0] - Datasource not bound doing JPA outside of container

rcarmichael do-not-reply at jboss.com
Thu Mar 20 15:43:53 EDT 2008


I'm trying to write JUnit tests for some of our JPA stuff. I'm essentially just trying to get an EntityManager for my persistence units from a standalone java app. I've tried this:


  | System.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
  | System.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
  | System.setProperty("java.naming.provider.url","jnp://localhost:1099");
  | 		
  | Persistence.createEntityManagerFactory("TheDAO");
  | 

but I get this:


  | - Could not find datasource: java:/MyDS
  | javax.naming.NameNotFoundException: MyDS not bound
  | 	at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
  | 	at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
  | 	at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
  | 	at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
  | 	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
  | 	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
  | 	at javax.naming.InitialContext.lookup(InitialContext.java:351)
  | 	at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
  | 	at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
  | 	at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
  | 	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
  | 	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
  | 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
  | 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
  | 	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
  | 	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
  | 	at com.test.Test.main(Test.java:23)
  | Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not find datasource
  | 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
  | 	at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
  | 	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
  | 	at com.test.Test.main(Test.java:23)
  | Caused by: org.hibernate.HibernateException: Could not find datasource
  | 	at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:56)
  | 	at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
  | 	at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
  | 	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:62)
  | 	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
  | 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
  | 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
  | 	... 3 more
  | Caused by: javax.naming.NameNotFoundException: CobraShadowDS not bound
  | 	at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
  | 	at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
  | 	at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
  | 	at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
  | 	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
  | 	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
  | 	at javax.naming.InitialContext.lookup(InitialContext.java:351)
  | 	at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
  | 	... 9 more
  | 

However using the JXMConsole I can clearly see that MyDS is in the java: namespace, so I am not sure how it could not be "bound". The persistence stuff works perfectly in-container, so I know that part is set up right.

Any ideas?

Thanks,
Ryan

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4138148#4138148

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4138148



More information about the jboss-user mailing list