facebook

Hibernate, Tomcat and InitialContextFactory [Closed]

  1. MyEclipse IDE
  2.  > 
  3. General Development
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #213942 Reply

    Javier Ramos
    Participant

    Hi,

    I am working on a web project that will be deployed to a Tomcat 5 server. The persistence is done with Hibernate. I want to use also tomcat’s built in connection pooling (DBCP), so I created a context configuration for my project in server.xml, including a JNDI entry for the DBCP data source.

    When creating the config file for Hibernate, I can set the JNDI name that I configured before, but I need to provide also an InitialContextFactory class. After searching the web I reached the conclusion that this class must be:

    org.apache.catalina.naming.java.javaURLContextFactory

    if my webapp is going to run inside Tomcat.

    The problem is that this does not work… when loading a page that acesses data I get:

    java.lang.ClassNotFoundException: org.apache.catalina.naming.java.javaURLContextFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:219)
    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:42)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:649)

    Can anyone help here? Am I doing something wrong? Should I be using some other InitialContextFactory class?

    Any help would be very much appreaciated.

    Thanks for your attention,

    Javier

    #213951 Reply

    snpe
    Member

    try set hibernate.connection.datasource parametar in your JNDI name
    Hibernate will choose default

    regards

    #213955 Reply

    Riyad Kalla
    Member

    Javier,
    Your file should look something like this:

    
    <hibernate-configuration>
    
        <session-factory>
    
            <property name="connection.datasource">java:comp/env/jdbc/quickstart</property>
            <property name="show_sql">false</property>
            <property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
    
            <!-- Mapping files -->
            <mapping resource="Cat.hbm.xml"/>
    
        </session-factory>
    
    </hibernate-configuration>
    

    No need for InitialContextFactory that I’m aware of.

    #213957 Reply

    Javier Ramos
    Participant

    This works, thanks.

    Javier

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Hibernate, Tomcat and InitialContextFactory [Closed]

You must be logged in to post in the forum log in