-->
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.  [ 3 posts ] 
Author Message
 Post subject: Problem with access to SessionFactory in JNDI, Tomcat 5.5
PostPosted: Mon Oct 09, 2006 6:31 am 
Newbie

Joined: Mon Oct 09, 2006 5:12 am
Posts: 2
Hi

I use
Hibernate-Version: 3.2.0.cr5
apache-tomcat-5.5.17

In hibernate.cfg.xml I put
Code:
<property name="hibernate.session_factory_name">HibernateSessionFactory</property>


Also made listener with code:
Code:
sessionFactory = new Configuration().configure().buildSessionFactory();


After this I receive SessionFactory by:
Code:
initCtx = new InitialContext();
SessionFactory ses = (SessionFactory) envCtx.lookup("HibernateSessionFactory");


So, where is the problem ? :)

I want to map SessionFactory object in JNDI with name "java:comp/env" for example.
When I change this in properties for "java:comp/env/HibernateSessionFactory" , I can't receive obect by name "java:comp/env/HibernateSessionFactory".

I try to use "ResourceLink" tag in context.xml file, but this is also didn't work (in debug mode i can found this object in 'bindings' map and list() also returned it, but lookup throw javax.naming.NameNotFoundException: Name HibernateSessionFactory is not bound in this Context)

Did anyone do something like this and it worked?

--------------------------------------------------
My files:
hibernate.cfg.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

    <session-factory>

       <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://localhost:5432/MunSol</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">bleble</property>
      <property name="hibernate.session_factory_name">HibernateSessionFactory</property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
    </session-factory>


</hibernate-configuration>

---------------------------------
web.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
   xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      <servlet>
   <servlet-name>Send Servlet</servlet-name>
      <servlet-class>a.servlet.SendServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
      <servlet-name>Send Servlet</servlet-name>
      <url-pattern>/send</url-pattern>
   </servlet-mapping>
   
   <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
   

   <listener>
      <listener-class>
         a.servlet.HibernateInitializerListener
      </listener-class>
   </listener>

</web-app>


---------------------------------------------
context.xml
Code:

<Context>     
      <ResourceLink name="HibernateSessionFactory"
            global="HibernateSessionFactory"
            type="org.hibernate.SessionFactory"/>

</Context>


-----------------------------------------------
SendServlet.java
public class SendServlet extends HttpServlet{
Code:
   public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      System.out.println("bleble");
      
      Context initCtx;
      try {
         initCtx = new InitialContext();
      
         NamingContext envCtx = (NamingContext)initCtx.lookup("java:comp/env");
         
         SessionFactory ses = (SessionFactory) envCtx.lookup("HibernateSessionFactory");
         
      } catch (NamingException e) {
         e.printStackTrace();
      }
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 6:41 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Tomcat has a read-only JNDI context, nobody (and not Hibernate) can bind anything there except Tomcat. Use an application server with a real JNDI implementation or a JNDI implementation like Suns FSContext.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 6:46 am 
Newbie

Joined: Mon Oct 09, 2006 5:12 am
Posts: 2
Hi,
thank you for fast answer !!

So it's mean, that i can register sessionFactory only with "simple" name like '<property name="hibernate.session_factory_name">HibernateSessionFactory</property>' ????

Regards
Ales' M.


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