-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Could not find datasource: java:/...
PostPosted: Fri Dec 14, 2007 5:31 am 
Newbie

Joined: Wed Mar 22, 2006 5:29 am
Posts: 3
Hello!

I'm facing a problem when I'm trying to connect the entity manager from a web service in a war file. My web service is a JAX-WS using the Provider< SOAPMessage >implementation.

JBoss (4.2.2.GA, Java 1.5.0_13, Ubuntu 7.10) starts up wihtout any problems. I can see that may datasource i deployed (I have a couple of other of these accessed from EJB:s) and they are working like a charm).

So when I just want to use the EntityManager from a web service provider in a war I get a
org.hibernate.HibernateException: Could not find datasource: java:/MyDs. I have included all Hibernate jars in the WEB-INF lib, so the shall be loaded first and override those jars exposed by JBoss. Please let me know if I'm wring here.

Here is my entity manager instantiation
Code:
private EntityManager entityManager = Persistence.createEntityManagerFactory("MyService").createEntityManager();


... and my persistence.xml file lokks like
Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
     http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
   version="1.0">
   <persistence-unit name="MyService"
      transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>
         java:/MyService-DS
      </jta-data-source>
      <properties>
         <property name="show_sql" value="true" />
         <property name="hibernate.format_sql" value="true" />
         <property name="hibernate.use_sql_comments" value="true" />
         <property name="hibernate.dialect"
            value="org.hibernate.dialect.MySQLDialect" />
      </properties>
   </persistence-unit>
</persistence>


The error I get is:
Code:
09:58:39,523 INFO  [NamingHelper] JNDI InitialContext properties:{}
09:58:39,523 INFO  [NamingHelper] JNDI InitialContext properties:{}
09:58:39,526 ERROR [SOAPFaultHelperJAXWS] SOAP request exception
javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not find datasource: java:/MyService-DS
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
...
Caused by: org.hibernate.HibernateException: Could not find datasource: java:/MyService-DS
        at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:59)
        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.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
        ... 36 more


Thank you all for your help!
/Oskar


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 14, 2007 7:48 am 
Beginner
Beginner

Joined: Tue Nov 27, 2007 9:44 am
Posts: 46
Hi,

have you defined your datasource in the JBoss AS?
http://www.jboss.org/wiki/Wiki.jsp?page=DSdotXML

Regards,
Frank


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 14, 2007 8:35 am 
Newbie

Joined: Wed Mar 22, 2006 5:29 am
Posts: 3
Yes! (of course I have)

To give some more info, the connection works if I put all connection parameters in the persistence.xml file (i.e. not using the jta functionality).

//Oskar


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 14, 2007 9:50 am 
Beginner
Beginner

Joined: Tue Nov 27, 2007 9:44 am
Posts: 46
Sorry, I just wanted to make sure you have.

To me this sounds like there's a problem with the datasource configuration in JBoss. Have you check the DS in the JMX console?

I can't tell you exactly how to check it right now, haven't got access to a JBoss server here.


Good Luck,
Frank


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 18, 2007 3:20 am 
Newbie

Joined: Wed Mar 22, 2006 5:29 am
Posts: 3
Hi again!

The data source source is deployed as it shall be. It is shown in the JMX-console and there is no problem with it. If I use the same datasource from an EJB (letting JBoss instantiate its own, Hibernate, entity manager), there is no problem. This is a Hibernate issue that I can't understand.

So, can this be a classloader problem? Are there any security constraints that I must look at to make Hibernate entity manager use the deployed data source? I bundle Hibernate in the war file (WEB-INF/lib) to make it possible to deploy this war file in any application server.

Cheers
/Oskar


Top
 Profile  
 
 Post subject: Re: Could not find datasource: java:/...
PostPosted: Tue May 05, 2009 8:53 pm 
Newbie

Joined: Tue May 05, 2009 8:01 pm
Posts: 1
Has anyone found a solution to this problem. I have been experiencing the same issue for 3 days trying to work it out.

my JTA datasource in persistence.xml just wont be found, have no idea whats going on but its exactly the same issue as above


Top
 Profile  
 
 Post subject: Re: Could not find datasource: java:/...
PostPosted: Wed Jul 22, 2009 6:05 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
I got this same problem, debugging it turns out that the datasource instance being returned from JBoss is "null",
which is causing the stacktraces posted above.
If the datasource configuration would have been wrong (like not deployed or being registered with a different name) the stacktrace would be caused by
Code:
Caused by: javax.naming.NameNotFoundException: MyService-DS not bound


I'm still walking in the dark about why I'm not getting the reference to the datasource, all cases I've found have this in common:
they are starting the EntityManagerFactory or SessionFactory from code, inside the context of some EJB environment.

This post was opened about a webservice endpoint, I've seen it happening inside a @Remote invoked bean and also inside a Quartz MDB bean.
Looking up an existing EMF or SF from JNDI or injection is fine, so when the container starts an EMF or SF the same datasource is not returning null.

anybody having some hints? I've also lost three days on this now.
Could it be some sort of "protection" from the AS? I understand it's not a best practice to load the EMF this way, but I'm needing it this way for now.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.