-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Configuration (three different cases)
PostPosted: Sat Feb 07, 2009 7:03 am 
Newbie

Joined: Sat Feb 07, 2009 3:18 am
Posts: 1
Location: Muntinlupa City
Hi Everyone!

I've been developing a small web application. This application implements the Multi-tiered architecture, so, i have chosen Hibernate as the data-tier of my application.

During the configuration of Hibernate, I committed some mistakes which produced some errors during the deployment, but fortunately i was able to find solution for it. However, I'm bit confused about few things and there's this one error that I can't fix, so I need your help. =)

For more info, the web server that i am using is Tomcat 5.5. I've already read the hibernate_reference and some tutorials including this site's articles: http://www.metaarchit.com/articles.html. The site created and demonstrated the creation of a web application that implements Hibernate. It is very easy to understand so I followed their pattern.

Question #1:
The basic structure of configuring hibernate.cfg.xml is to place the hibernate connection inside this file. However, somebody suggested to place the data connection inside the context.xml so that the data connection will be loaded at once. Thinking that it may improve the performance of my web application, I followed the advice.

However, upon reading this phrase in your article I become confused.

Source: http://www.hibernate.org/114.html
Quote:
If you use Hibernate on Tomcat you don't have to use Tomcat's JNDI-bound JDBC connections. You can let Hibernate manage the JDBC connection pool. This works on all versions of Tomcat and is very easy to configure.


Does the quoted phrase above tells me that it's the only option I can use to define my connection properties because i'm using Tomcat? Considering that I'm using Tomcat, is it okay to put my data connections inside context.xml?

NOTE: The data connection works fine so far but I insist that someone may answer the questions above to clarify my confusion. What really confused me is the next question.

Question #2:
I am planning to make use of a Helper class that will manage the lazyInitialization of my associations so that i will abide to the application's architecture. But for some reasons and for the meantime, I want to try the Open Session in View even though I'm using the multi-tiered approach. Hehe

First, I want to show you what I've written in my Filter class and its configuration in hibernate and deployment descriptor.

Filter class: HibernateFilter.class
Code:
public class HibernateSessionFilter implements Filter {
   
   public void doFilter(ServletRequest request, ServletResponse response,   FilterChain chain) throws IOException, ServletException {
      SessionFactory factory = HibernateSessionFactory.getSessionFactory();
      Session session = factory.getCurrentSession();
      Transaction transact = null;
      try{
         transact = session.beginTransaction();
         if(request.equals(null) || response.equals(null)) {
            chain.doFilter(request, response);
         }
         transact.commit();
      }catch(Throwable throwable){
         if(transact.isActive()){
            transact.rollback();
         }
         throw new ServletException(throwable);
      }
   }

   @Override
   public void init(FilterConfig arg0) throws ServletException {
      // TODO       
   }

   @Override
   public void destroy() {
      // TODO
   }
}



web.xml
Code:
<!-- Filter Mapping -->
  <filter>
     <filter-name>HibernateSessionFilter</filter-name>
     <filter-class>cisma.HibernateSessionFilter</filter-class>
  </filter>
  <filter-mapping>
     <filter-name>HibernateSessionFilter</filter-name>
     <url-pattern>/*</url-pattern>
  </filter-mapping>



hibernate.cfg.xml
Code:
        <property name="hibernate.current_session_context_class">thread</property>


The tutorial said that i must define the value of current_session_context_class as thread to tell Hibernate that it should be session bound with the current thread.

The problem occurs when accessing the application. The first page of the application produces an error page telling:

Quote:
org.hibernate.HibernateException: No TransactionManagerLookup specified org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:503)
cisma.HibernateSessionFilter.doFilter(HibernateSessionFilter.java:27)
[/url]

It said in some forums that if i put value to my context class the manager_lookup_class becomes non-optional. If my context class is jta, i must chose the TransactionManager that corresponds to the application server that I am using. What about in my case? I'm using thread as context class and Tomcat as my web/application server. What TransactionManageLookup should I use?

Question #3:
Since I'm using Tomcat, do I need to have the SessionFactory bound in JNDI?

If yes, aside from specifying this property to the hibernate.cfg.xml:
Code:
<property name="hibernate.session_factory_name">java:hibernate/HibernateSessionFactory</property>

what else do I need to configure? Do I need to configure something in the web.xml?

Hope I explained my questions clearly. If you might get confused with my question please don't hesitate to ask. I really need ANSWERS so that I may complete the application.

And, thanks for those who patiently read my questions. May all the knowledge to answer my questions be with you!!!

Thanks =)

_________________
Donna Agtang

"Enjoy what you do and it'll be easy for you!"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.