You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by SofIAm <so...@yahoo.com> on 2009/05/19 18:10:31 UTC

Cannot find datasource error...Please help!

Sorry if I'm posting in the wrong forum, but I'm desperate at this point...
Please help me figure out how or why I'm not binding my datasource and
beans.  Please forgive for such a long message.

I'm trying to deploy my container-managed EJB3 in Eclipse running on JBoss
4.2/SQLServer 2005. 
For some reason, I cannot bind my beans in JBoss, and it's not finding the
datasource. 


Here's the error:

 Could not find datasource: java:/WinTrackDS
javax.naming.NameNotFoundException: WinTrackDS 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(Unknown Source)
	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
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
	at tester.TestEJB3Controller.<init>(TestEJB3Controller.java:17)
	at tester.MainTemp.main(MainTemp.java:34)
org.hibernate.HibernateException: Could not find datasource


jmx-console:

jboss.jca
name=WinTrackDS,service=DataSourceBinding 
name=WinTrackDS,service=LocalTxCM 
name=WinTrackDS,service=ManagedConnectionFactory

My ejb is not under service=JNDIView .


I added mssql-ds.xml in my Jboss dir default\deploy:

<datasources>
  <local-tx-datasource>
    <jndi-name>WinTrackDS</jndi-name>
    <use-java-context>false</use-java-context>
   
<connection-url>jdbc:sqlserver://localhost:1433;DatabaseName=WinTrack</connection-url>
   
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
    <user-name>sa</user-name>
    <password>sa</password>
        <!-- sql to call when connection is created
        <new-connection-sql>some arbitrary sql</new-connection-sql>
        -->

        <!-- sql to call on an existing pooled connection when it is
obtained from pool 
        <check-valid-connection-sql>some arbitrary
sql</check-valid-connection-sql>
        -->
 </local-tx-datasource>
</datasources>

In META-INF of my project, jbosscmp-jdbc.xml:
<jbosscmp-jdbc>

  	<defaults>
      	<datasource>java:/WinTrackDS</datasource>
      	<create-table>false</create-table>
      	<remove-table>false</remove-table>
      	<!-- optional since 4.0 <datasource-mapping>SQL Server
SQL</datasource-mapping> -->
   	</defaults>			
 	<enterprise-beans>
		<entity>
			<ejb-name>TestEJB3</ejb-name>
			<table-name>PEOPLE</table-name>
			<cmp-field>
				<field-name>ID</field-name>
				<column-name>PERSON_KEY</column-name>
			</cmp-field>
			<cmp-field>
				<field-name>firstname</field-name>
				<column-name>FIRSTNAME</column-name>
			</cmp-field>
		</entity>
	</enterprise-beans>
</jbosscmp-jdbc>

In META-INF, persistance.xml:

<persistence>

	<persistence-unit name="TestEJB3-PU">
    	<jta-data-source>java:/WinTrackDS</jta-data-source>
    	<properties>
 			<property name="hibernate.hbm2ddl.auto" value="update" />
			<property name="hibernate.show_sql" value="false" />
			<property name="hibernate.dialect"
value="org.hibernate.dialect.SQLServerDialect" />
			<property name="hibernate.connection.driver_class"
value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
			<property name="hibernate.connection.username" value="sa" />
			<property name="hibernate.connection.password" value="sa" />
			<property name="hibernate.connection.url"
value="jdbc:sqlserver://localhost:1433" />
		</properties>
  	</persistence-unit>
  	
</persistence>

Here's my test code:

public class MainTemp {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    	
 
       List list;
        String[] test;
        Iterator iterator;

        try {
            TestEJB3Controller tc = new TestEJB3Controller();
            list = tc.getPeople();
            iterator = list.iterator();
             while (iterator.hasNext()){
                System.out.println("Main: People "+iterator.next()+" ");
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }

}

Here's the controller:

@PersistenceUnit
	EntityManagerFactory emf;
	EntityManager em;

	public TestEJB3Controller () throws Exception {

		emf = Persistence.createEntityManagerFactory("TestEJB3-PU");
	    em = emf.createEntityManager();
	}
	public List getPeople() throws PersonNotFoundException {
		try {
			em.getTransaction().begin();
	        List list = em.createQuery("select c from TestEJB3 
c").getResultList();
	        em.getTransaction().commit();
	        return list;
		} catch(Exception ex){
			em.getTransaction().rollback();
	        ex.printStackTrace();
	        throw new PersonNotFoundException("Could not find person: "
	        		+ ex.getMessage()+ex.toString());
	        //} finally {
	            //em.close();
	        }
	    }
	 
}



Any ideas would be greatly appreciated.
-- 
View this message in context: http://www.nabble.com/Cannot-find-datasource-error...Please-help%21-tp23619498p23619498.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Cannot find datasource error...Please help!

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Tue, May 19, 2009 at 6:10 PM, SofIAm <so...@yahoo.com> wrote:
>
> Sorry if I'm posting in the wrong forum, but I'm desperate at this point...
> Please help me figure out how or why I'm not binding my datasource and
> beans.  Please forgive for such a long message.
>
> I'm trying to deploy my container-managed EJB3 in Eclipse running on JBoss
> 4.2/SQLServer 2005.
> For some reason, I cannot bind my beans in JBoss, and it's not finding the
> datasource.
...
> Any ideas would be greatly appreciated.

Hi,

The only answer I'd come up with here, in OpenEJB mailing list, would
be to try out to run the beans in OpenEJB and see if it helped to sort
out the main issue. It might reveal some interesting stuff.

Jacek

-- 
Jacek Laskowski
Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl