cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brent Johnson <bljohn...@gmail.com>
Subject Re: Using Hibernate via Java, not Flow
Date Tue, 19 Apr 2005 19:37:15 GMT
I've gone through the tutorial on the Wiki and everything seems to be
going fine.  Here's one question I have for people who have used this
tutorial as a basis for implementing Hibernate with Cocoon:

Is there a good way to open the hibernate session in Java rather than
in Flowscript as the tutorial suggests?  For example, how would I
handle the "hs" global variable, and saving the Hibernate session in
the user session?

Thanks,

- Brent

On 4/18/05, Adam Ratcliffe <adam@prema.co.nz> wrote:
> Hi Brent
> 
> Yes this is possible, I'm doing it this way with an existing project, for
> similar reasons to yours. Longer term you should probably look at moving to
> Spring however for your hibernate support.
> 
> I'm using the Avalon Hibernate library (which I believe is now deprecated) to do
> the work that's done by the HibernateFactory class described on the wiki:
> http://wiki.apache.org/cocoon/CocoonAndHibernateTutorial
> 
> I have a PersistenceHelper class that has generic CRUD methods like addEntity(),
> updateEntity(), removeEntity() that hides the hibernate stuff. This is an Avalon
> component that is looked up in Java code like this:
> 
> PersistenceHelper persistenceHelper = (PersistenceHelper)
> serviceManager.lookup(PersistenceHelper.ROLE);
> 
> A ServletFilter closes the hibernate session after the request has been
> processed.
> 
> > -----Original Message-----
> > From: Brent Johnson [mailto:bljohnson@gmail.com]
> > Sent: Tuesday, 19 April 2005 6:32 a.m.
> > To: users@cocoon.apache.org
> > Subject: Re: Using Hibernate via Java, not Flow
> >
> >
> > Is there a way to use the filter approach to closing hibernate
> > sessions without using Spring?  I'd rather not introduce a whole new
> > framework this late into the development cycle.  Is it possible to use
> > Hibernate with Cocoon without Spring, but still encapsulating all
> > Hibernate calls in Java objects (not flow), and actually be able to
> > close the Hibernate sessions?
> >
> > Our current project uses 21 different beans (in this case Hibernate
> > POJO's) to access 29 different database tables.  So I'm guessing
> > trying to implement Spring at this late point in the development cycle
> > would not be trivial.
> >
> > Thanks,
> >
> > - Brent
> >
> > On 4/14/05, JD Daniels <jd@kismetsoftware.com> wrote:
> > > I didn't see the need for a cocoon component. I looked again, but still
> > > can't find the article that got me going... basically here is my setup:
> > >
> > > web.xml:
> > >
> > > <!-- Location of the application context configuration file -->
> > >      <context-param>
> > >          <param-name>contextConfigLocation</param-name>
> > >          <param-value>WEB-INF/ApplicationContext.xml</param-value>
> > >      </context-param>
> > >
> > > <!-- Filter Configuration ========================================== -->
> > >      <filter>
> > >          <filter-name>OpenSessionInViewFilter</filter-name>
> > >
> > >
> > <filter-class>org.springframework.orm.hibernate.support.OpenSessionInV
> > iewFilter</filter-class>
> > >          <init-param>
> > >              <param-name>singleSession</param-name>
> > >              <param-value>false</param-value>
> > >          </init-param>
> > >      </filter>
> > >
> > >      <filter-mapping>
> > >          <filter-name>OpenSessionInViewFilter</filter-name>
> > >          <url-pattern>/*</url-pattern>
> > >      </filter-mapping>
> > >
> > > <!-- Listener Configuration ========================================== -->
> > >      <listener>
> > >
> > >
> > <listener-class>org.springframework.web.context.ContextLoaderListener<
> > /listener-class>
> > >      </listener>
> > >
> > > Applicationcontext.xml:
> > >
> > > <beans>
> > >    <!-- The data source -->
> > >      <bean class="org.apache.commons.dbcp.BasicDataSource"
> > > destroy-method="close" id="DataSource">
> > >          <property name="driverClassName">
> > >              <value>com.mysql.jdbc.Driver</value>
> > >          </property>
> > >          <property name="url">
> > >              <value>jdbc:mysql://dbplace.com/db</value>
> > >          </property>
> > >          <property name="username">
> > >              <value>dbuser</value>
> > >          </property>
> > >          <property name="password">
> > >              <value>dbpas</value>
> > >          </property>
> > >      </bean>
> > >
> > > <!-- The transaction manager -->
> > >      <bean
> > > class="org.springframework.orm.hibernate.HibernateTransactionManager"
> > > id="transactionManager">
> > >          <property name="sessionFactory">
> > >              <ref bean="sessionFactory"/>
> > >          </property>
> > >      </bean>
> > >
> > >    <!-- The session factory -->
> > >      <bean
> > > class="org.springframework.orm.hibernate.LocalSessionFactoryBean"
> > > id="sessionFactory">
> > >          <property name="mappingResources">
> > >              <list>
> > >    <!-- Authenticator Mapping -->
> > >      <value>com/kismetsoftware/authenticator/model/User.hbm.xml</value>
> > >      <value>com/kismetsoftware/authenticator/model/Role.hbm.xml</value>
> > >
> > > </list>
> > >          </property>
> > >          <property name="hibernateProperties">
> > >              <props>
> > >                  <prop
> > > key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
> > >              </props>
> > >          </property>
> > >          <property name="dataSource">
> > >              <ref bean="DataSource"/>
> > >          </property>
> > >      </bean>
> > >
> > >    <!-- Authenticator Beans -->
> > >      <bean
> > >
> > class="com.kismetsoftware.authenticator.spring.dao.hibernate.UserHibernateDAO"
> > > id="userDAO">
> > >          <property name="sessionFactory">
> > >              <ref bean="sessionFactory"/>
> > >          </property>
> > >      </bean>
> > >
> > >      <bean
> > >
> > class="com.kismetsoftware.authenticator.spring.dao.hibernate.RoleHibernateDAO"
> > > id="roleDAO">
> > >          <property name="sessionFactory">
> > >              <ref bean="sessionFactory"/>
> > >          </property>
> > >      </bean>
> > >
> > >      <bean
> > >
> > class="com.kismetsoftware.authenticator.spring.service.AuthenticatorSe
> > rviceImpl"
> > > id="authenticatorServiceTarget" init-method="initialize">
> > >          <property name="userDAO">
> > >              <ref bean="userDAO"/>
> > >          </property>
> > >          <property name="roleDAO">
> > >              <ref bean="roleDAO"/>
> > >          </property>
> > >      </bean>
> > >
> > >      <bean
> > >
> > class="org.springframework.transaction.interceptor.TransactionProxyFac
> > toryBean"
> > > id="authenticatorService">
> > >          <property name="transactionManager">
> > >              <ref bean="transactionManager"/>
> > >          </property>
> > >          <property name="target">
> > >              <ref bean="authenticatorServiceTarget"/>
> > >          </property>
> > >          <property name="transactionAttributes">
> > >              <props>
> > >                  <prop key="create*">PROPAGATION_REQUIRED</prop>
> > >                  <prop key="read*">PROPAGATION_REQUIRED</prop>
> > >                  <prop key="update*">PROPAGATION_REQUIRED</prop>
> > >                  <prop key="delete*">PROPAGATION_REQUIRED</prop>
> > >                  <prop key="initializeDatabase">PROPAGATION_REQUIRED</prop>
> > >              </props>
> > >          </property>
> > >      </bean>
> > >
> > > </beans>
> > >
> > > So in flow, you just get a handle on the service beans, which handle all
> > > the work, and lazy initialization is no longer an issue.
> > >
> > > JD
> > >
> > >
> > > Jakub Kaniewski wrote:
> > > > Brent Johnson wrote:
> > > >
> > > >> I searched the Wiki for "servletfilter", "servlet-filter", "servlet
> > > >> filter" and didn't find anything.  Is there an example of closing
> > > >> Hibernate sessions using a servlet filter on the Wiki?
> > > >>
> > > >>
> > > > Here is the wiki article I mentioned before -
> > > >
> http://wiki.apache.org/cocoon/CocoonAndHibernateTutorial?highlight=%28Hibernate%
> 29
> > >
> > >
> > > J.K.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > > For additional commands, e-mail: users-help@cocoon.apache.org
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message