I am new to resin and am trying to get Hibernate to work with it. I am running into some problems with the JNDI lookup of the data source. I have a special case where I need to dynamically create an EntityManager with passing in the url property. so when I set up my web.xml it looks like this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://caucho.com/ns/resin">
<database jndi-name="jdbc/evolution">
<driver>
<type>org.postgresql.Driver</type>
</driver>
</database>
<ejb-server data-source="jdbc/evolution"/>
</web-app>
and my persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="evolution">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<!--<provider>com.caucho.amber.manager.AmberPersistenceProvider</provider>-->
<!--<jta-data-source>jdbc/evolution</jta-data-source>-->
<jta-data-source>java:comp/env/jdbc/evolution</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
</properties>
</persistence-unit>
</persistence>
here is the code I am using to get the Entity manager
Code:
public class DatabaseConnectionFactory {
public static EntityManager createManager(String databaseName) {
EntityManagerFactory emf;
Map properties = new HashMap();
properties.put("javax.persistence.jdbc.url", "jdbc:postgresql://localhost:5432/" + databaseName);
properties.put("javax.persistence.jdbc.user", "postgres");
properties.put("javax.persistence.jdbc.password", "");
properties.put("javax.persistence.jdbc.driver", "org.postgresql.Driver");
emf = Persistence.createEntityManagerFactory("evolution", properties);
return emf.createEntityManager();
}
}
when it tries to create the entity manager I get a
javax.naming.NameNotFoundException: java:comp/env/jdbc/evolutionI have also tried putting in jdbc/evolution in the jta-data-source tag in the persistence.xml. The weird thing is when I first hit a break point in a servlet and lookup the "java:comp/env/jdbc/evolution" object myself through InitialContext it finds it, but once it gets into the hibernate code it can't. Anyone have any ideas why?