You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Name

Hibernate Session Plugin for Struts 2

Publisher

José Yoshiriro

License

Open Source (ASL2)

Version

1.0

Compatibility

Struts 2.0.9+

Homepage

http://code.google.com/p/hibernatesession-plugin-for-struts2/

Download

http://code.google.com/p/hibernatesession-plugin-for-struts2/downloads/list

Error formatting macro: rate: java.lang.NoSuchMethodError: 'java.lang.String com.atlassian.confluence.setup.BootstrapManager.getDomainName()'

Overview

Hibernate Session Plugin for Struts 2 There is the best practice the use of design pattern "open session in view" for WEB applications with Hibernate.This Plugin offers a Interceptor that open a Hibernate Session, put this in the Action Value Stack and close (or not) this after Action invokation.

Features

  • Interceptor for "open session in view" pattern with Hibernate Core

Usage

Google Code Wiki

Parameters:

  • sessionFactoryClass- Project Hibernate Session Factory
    Example: com.myproject.hibernate.HibernateSessionFactory?
  • sessionSource - Getter in the class named in sessionFactoryClass that returns a Hibernate Sessoin
    Example: session (indicates the getSessao() method)
  • target - Target object in Action
    Examples: hibernateSession; facade.hibernateSession
  • staticGetSessionMethod - Is the method named in sessionSource static?. Optional. Default true.
  • closeSessionAfterInvoke - Close the Hibernate Session after Action invokation? Optional. Default true.

Example

Example 1:

<package name="principal" extends="struts-default" namespace="/">
    	<interceptors>
    		<interceptor name="hibernateInterceptor" class="com.googlecode.s2hibernate.struts2.plugin.s2hibernatesession.HibernateSessionInterceptor">
	    		<param name="target">facade.session</param>
	    		<param name="sessionFactoryClass">hibernate.factory.HibernateSessionFactory</param>
	    		<param name="sessionSource">session</param>
	    		<param name="staticGetSessionMethod">true</param>
	    		<param name="closeSessionAfterInvoke">true</param>
    		</interceptor>
    	</interceptors>

        <action name="teste" class="actions.TestAction">
	    	<interceptor-ref name="hibernateInterceptor"/>
        	<result>/resultpage.jsp</result>
        </action>

 </package> 


 Example 2: 

 <package name="principal" extends="struts-default" namespace="/">
    	<interceptors>
    		<interceptor name="hibernateInterceptor" class="com.googlecode.s2hibernate.struts2.plugin.s2hibernatesession.HibernateSessionInterceptor">
	    		<param name="target">facade.session</param>
	    		<param name="sessionFactoryClass">hibernate.factory.HibernateSessionFactory</param>
	    		<param name="sessionSource">session</param>
    		</interceptor>

		<interceptor-stack name="basicStackWithHibernateSession">
				<interceptor-ref name="hibernateInterceptor"/>
				<interceptor-ref name="basicStack"/>
		    </interceptor-stack>

		    <interceptor-stack name="defaultStackWithHibernateSession">
				<interceptor-ref name="hibernateInterceptor"/>
				<interceptor-ref name="defaultStack"/>
		    </interceptor-stack>
    	</interceptors>

	<action name="enterData" class="actions.TestAction">
	    	<interceptor-ref name="basicStackWithHibernateSession"/>
        	<result>/inputpage.jsp</result>
        </action>

        <action name="submitData" class="actions.TestAction" method="doit">
	    	<interceptor-ref name="defaultStackWithHibernateSession"/>
        	<result>/resultpage.jsp</result>
        </action>

 </package>

Installation

This plugin can be installed by copying the plugin jar into your application's /WEB-INF/lib directory. No other files need to be copied or created.

Version History

Version

Date

Author

Notes

1.5c

Dec 03, 2008

José Yoshiriro

Multiple XML packages extend and super class targets for Hibernate Session allowed

1.5b

Oct 24, 2008

José Yoshiriro

Wildcard allowed for Hibernate Session Target

1.5

Oct 21, 2008

José Yoshiriro

Configuration Constants by Project

1.0

Oct 08, 2008

José Yoshiriro

Initial release

  • No labels