-->
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.  [ 2 posts ] 
Author Message
 Post subject: Resin Server and Hibernate NameNotFoundException
PostPosted: Tue Feb 25, 2014 8:48 pm 
Newbie

Joined: Tue Feb 25, 2014 8:35 pm
Posts: 2
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/evolution

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?


Top
 Profile  
 
 Post subject: Re: Resin Server and Hibernate NameNotFoundException
PostPosted: Wed Feb 26, 2014 2:43 pm 
Newbie

Joined: Tue Feb 25, 2014 8:35 pm
Posts: 2
After getting enough sleep last night I realized that I was trying to mix 2 technologies and that I did not need the jta-data-source at all. Since I was only needing the persistence.xml to create me a persistence-unit and then supply the rest of the connection properties in code. I removed the jta-data-source and all was happy after that. So my persistence.xml now looks like

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>
        <properties>
             <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
        </properties>
    </persistence-unit>
</persistence>


now I get a result back from teh Entity Manager. Yipee!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.