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