I'd be interested in your code, and would love to come up with a *recommended*
way to implement Hibernate in webapps.

However, I prefer to keep any database connections out of my web tier.  Since
I only use them in my dao's that's where I prefer to use them.  I also am
using a Business Delegate to talk from my Web Tier to my DAOs.  I like this
b/c it makes it easy to test each different layer with JUnit and I feel like
I'm following recommended patterns.  I don't like this because it feels like
it takes forever to implement a new table to talk to.  A big reason for
implementing business delegates and dao's is to allow for re-usability, but
most of the projects I've been on only ever talk to the DB through the web. 
Here's to hoping my "patterns" payoff someday.

That being said, I modified my HibernateSession object to allow for both JNDI
and JUnit type testing.  Please let me know if you see any issues in my
implementation.

Thanks,

Matt

> Hi Matt,
> 
>  From your example code that you posted, it doesn't seem like you were  
> ever closing the sessions you opened.  Is this true, or are you perhaps  
> doing it somewhere else in your code?
> 
> The way that I handle Hibernate sessions in all of my applications is  
> to use a ServletFilter that opens a Hibernate session at the beginning  
> of the request, and then closes the Hibernate session at the end of the  
> request.  It makes everything so much cleaner if you can just assume  
> that that Hibernate session will be there for you whenever you need it,  
> and that it will be closed when you are done using it.
> 
> If you want, I can send you a code snippet.   Just let me know...
> 
> I don't know if you have the same situation that I have, but for half  
> of my requests, I don't actually need the Hibernate session, so I  
> recently enhanced my ServletFilter to actually create a Proxy object  
> that looks like a Hibernate session.  If and when my application tries  
> to call a method on the Proxy object, then the Proxy object initialized  
> the session, and away we go, otherwise we never actually waste the  
> effort of opening a database connection.
> 
> I would think that a combination of my ServletFilter approach and your  
> current ThreadLocal approach would take care of all of your problems.
> 
> Regards,
> Jon...
> 
> Let me know if you want to
> On Thursday, January 2, 2003, at 09:01  PM, Matt Raible wrote:
> 
> > I *think* I fixed this problem by implementing a Connection Pool in  
> > Tomcat and
> > configuring Hibernate with a HibernationSession (using ThreadLocal) and
> > talking to Oracle using that method.  Seems to only open one  
> > connection now.
> >
> > Thanks,
> >
> > Matt
> >
> >> I'm getting the following error when using Hibernate as my persistence
> >> layer:
> >>
> >> java.sql.SQLException: ORA-02391: exceeded simultaneous  
> >> SESSIONS_PER_USER
> >> limit ORA-02063: preceding line from NAS_AC_72
> >> ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit ORA-02063:
> >> preceding line from NAS_AC_72
> >>
> >> Could this be caused by Hibernate?  I'm hoping not, but I don't know  
> >> enough
> >> about it to argue with the DBA that Hibernate (and my code) is not the
> >> problem.  Here's is a sample class I'm using to connect:
> >>
> >> public class ChangeRequestDAOHibernate extends BaseDAOHibernate  
> >> implements
> >> ChangeRequestDAO {
> >>     private static SessionFactory sessionFactory;
> >>     private static Datastore datastore;
> >>     private Log log =  
> >> LogFactory.getLog(ChangeRequestDAOHibernate.class);
> >>
> >>     public ChangeRequestDAOHibernate() throws DAOException {
> >>         try {
> >>             datastore = Hibernate.createDatastore();
> >>
> >> datastore.storeClass(com.cable.comcast.dmc.itd.cct.persistence.ChangeR 
> >> equest
> >> .class);
> >>
> >>             // build a SessionFactory
> >>             sessionFactory = datastore.buildSessionFactory();
> >>         } catch (MappingException e) {
> >>             throw new DAOException(e);
> >>         } catch (HibernateException e) {
> >>             throw new DAOException(e);
> >>         }
> >>     }
> >>    /**
> >>     * @see
> >> com.cable.comcast.dmc.itd.cct.persistence.ChangeRequestDAO#getHeadends 
> >> (MSO)
> >>     */
> >>    public List getHeadendsForMSO(MSO mso) throws DAOException {
> >>            Session ses = null;
> >>            List headendList = null;
> >>            
> >>            try {
> >>                    ses = sessionFactory.openSession();
> >>
> >>                    List changeRequests =
> >>                            (List) ses.find("from cr in class
> >> com.cable.comcast.dmc.itd.cct.persistence.ChangeRequest where  
> >> cr.msoId=?",
> >>                                            mso.getId(),
> >> Hibernate.LONG);
> >>                                                            
> >>                    if ((changeRequests == null) ||
> >> (changeRequests.size() == 0)) {
> >>                            log.warn("No headends found for msoId: " +
> >> mso.getId());
> >>                            return new ArrayList();
> >>                    }
> >>                    
> >>                    // if results are found, look up the headend names
> >> and build a list of headend objects
> >>                    LookupDAO lookupDAO = new LookupDAOHibernate();
> >>                    List headendIds = new ArrayList();
> >>                    
> >>                    // loop though the change requests and build a list
> >> of headends
> >>                    for (int i=0; i < changeRequests.size(); i++) {
> >>                            ChangeRequest cr = (ChangeRequest)
> >> changeRequests.get(i);
> >>                            Headend h = new Headend();
> >>                            h.setId(cr.getHeadendId());             
> >>                            headendIds.add(h);              
> >>                    }
> >>                    
> >>                    headendList = lookupDAO.getHeadendNames(headendIds);
> >>
> >>            } catch (Exception e) {
> >>                    try {
> >>                            ses.connection().rollback();
> >>                    } catch (Exception ex) {
> >>                            e.printStackTrace();
> >>                    }
> >>
> >>                    throw new DAOException(e);
> >>            } finally {
> >>                    try {
> >>                            ses.close();
> >>                    } catch (Exception ex) {
> >>                            ex.printStackTrace();
> >>                    }
> >>            }
> >>
> >>            return headendList;
> >>
> >>    }
> >>
> >> }
> >>
> >> -------------------------------------------------------
> >> This sf.net email is sponsored by:ThinkGeek
> >> Welcome to geek heaven.
> >> http://thinkgeek.com/sf
> >> _______________________________________________
> >> hibernate-devel mailing list
> >> [EMAIL PROTECTED]
> >> https://lists.sourceforge.net/lists/listinfo/hibernate-devel
> >
> >
> >
> > -- Matt Raible, Raible Designs, Morrison CO US
> > -- Tel: +1 303 979-5340
> > -- Mob: +1 720 560-8460
> > -- Fax: +1 508 256-6471
> > -- Web: http://www.raibledesigns.com
> >
> >
> > -------------------------------------------------------
> > This sf.net email is sponsored by:ThinkGeek
> > Welcome to geek heaven.
> > http://thinkgeek.com/sf
> > _______________________________________________
> > hibernate-devel mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/hibernate-devel



-- Matt Raible, Raible Designs, Morrison CO US
-- Tel: +1 303 979-5340
-- Mob: +1 720 560-8460
-- Fax: +1 508 256-6471
-- Web: http://www.raibledesigns.com

Attachment: HibernateSession.java
Description: Binary data

Reply via email to