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 Mon, 18 Apr 2005 18:32:01 GMT
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.OpenSessionInViewFilter</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.AuthenticatorServiceImpl"
> 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.TransactionProxyFactoryBean"
> 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


Mime
View raw message