title: Hibernate and Resin working together
body: <p>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 keep getting "javax.naming.NameNotFoundException".  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</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://caucho.com/ns/resin"&gt;
      &lt;database jndi-name="jdbc/evolution"&gt;
          &lt;driver&gt;
              &lt;type&gt;org.postgresql.Driver&lt;/type&gt;
          &lt;/driver&gt;
      &lt;/database&gt;
  
      &lt;ejb-server data-source="jdbc/evolution"/&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>and my persistence.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt;
      &lt;persistence-unit name="evolution"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;!--&lt;provider&gt;com.caucho.amber.manager.AmberPersistenceProvider&lt;/provider&gt;--&gt;
          &lt;!--&lt;jta-data-source&gt;jdbc/evolution&lt;/jta-data-source&gt;--&gt;
          &lt;jta-data-source&gt;java:comp/env/jdbc/evolution&lt;/jta-data-source&gt;
          &lt;properties&gt;
               &lt;property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>here is the code I am using to get the Entity manager:</p>
  
  <pre><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();
      }
  }
  </code></pre>
  
  <p>when it tries to create the entity manager I get a </p>
  
  <p><em>javax.naming.NameNotFoundException: java:comp/env/jdbc/evolution</em></p>
  
  <p>I 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?</p>