SSH framework of a combination of: Hibernate.cfg.xml from Hibernate to manage
Description: I developed environment: MyEclipse5.5 with JDK1.5
1, should first write the packet
com.mengya.entity: is this package
com.mengya.dao: DAO interface package
com.mengya.dao.imple entity package
com.megnya.util: uitl package
2, together with Spring support
3, together with Struts support
4, together with the Hibernate support
5, from Hibernate to create entity classes and DAO
Dao can you delete method in heavy-duty, to remove the object from the ID generated by the DAO interface, respectively, out of their assigned com.mengya.dao.imple package with com.megnya.dao
6, in the Spring into the applicationContext.xml in the applicationContext-beans.xml (regular beans)
And applicationContext-comon.xml (common beans) (personal habits, you can not separate)
7, modify applicationContext-comon.xml have DTD
Amended to read:
<beans xmlns = " "
xmlns: xsi = " "
xmlns: aop = " "
xmlns: tx = " "
xsi: schemaLocation = "
">
Write back if this is more convenient to write
applicationContext-comon.xml final as follows:
<? xml version = "1.0" encoding = "UTF-8"?>
<beans xmlns = " "
xmlns: xsi = " "
xmlns: aop = " "
xmlns: tx = " "
xsi: schemaLocation = "
">
<! - Configuration of the part of the public ->
<! - Configuration sessionFactory ->
<bean
>
<property name = "configLocation"
value = "classpath: hibernate.cfg.xml">
</ property>
</ bean>
<! - Configure the transaction manager ->
<bean>
<property name="sessionFactory" ref="sessionFactory" />
</ bean>
<! - The spread of properties to configure Services ->
<tx:advice transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="merge" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</ tx: attributes>
</ tx: advice>
<! - Configuration AOP ->
<aop:config>
<! - Com.mengya.dao.imple in all categories, all categories of all the methods (.. that any form of parameters) are the starting point poincut ->
<aop:pointcut expression="execution(* com.mengya.dao.imple.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allMethod"/>
</ aop: config>
</ beans>
8, the action with Struts and actionForm
Hibernate in actionForm generated in the package Javabean
Modify struts-config.xml in the type of action will be com.mengya.struts.action.StuAction amended to: org.springframework.web.struts.DelegatingActionProxy
9, in the Spring of action in the Struts configuration
Struts in action change the type value: org.springframework.web.struts.DelegatingActionProxy (Acting)
<bean>
<property name="sessionFactory">
<ref bean="sessionFactory" />
</ property>
</ bean>
Note: DAO should inherit HibernateDaoSupport
<! - Struts configuration of the action, bean the name value for the action of the path ->
<bean name="/stu">
<property name="studao" ref="StudentDAO" />
</ bean>
10, configured in web.xml
<! - Using Spring to provide the encoding of the filter ->
<filter>
<filter-name> springfitler </ filter-name>
<filter-class> org.springframework.web.filter.CharacterEncodingFilter </ filter-class>
<init-param>
<param-name> encoding </ param-name>
<param-value> gbk </ param-value>
</ init-param>
</ filter>
<filter-mapping>
<filter-name> springfiter </ filter-name>
<url-pattern> / * </ url-pattern>
</ filter-mapping>
<! - If not in the web.xml to configure the following contents:
<context-param>
<param-name> contextConfigLocation </ param-name>
<param-value> classpath *: applicationContext-*. xml </ param-value>
</ context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ listener>
->
Is coupled with the struts-config.xml
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="classpath*:applicationContext-*.xml"/>
</ plug-in>
11, well. OK, portfolio success!
Personal Note: After the collection may be wrong
1, may be less commons-pool-1.3.jar package (MyEclipse5.5)
2, may be necessary to re-build hibernate-annotations.jar package (MyEclipse5.1)
Description: I developed environment: MyEclipse5.5 with JDK1.5
1, should first write the packet
com.mengya.entity: is this package
com.mengya.dao: DAO interface package
com.mengya.dao.imple entity package
com.megnya.util: uitl package
2, together with Spring support
3, together with Struts support
4, together with the Hibernate support
5, from Hibernate to create entity classes and DAO
Dao can you delete method in heavy-duty, to remove the object from the ID generated by the DAO interface, respectively, out of their assigned com.mengya.dao.imple package with com.megnya.dao
6, in the Spring into the applicationContext.xml in the applicationContext-beans.xml (regular beans)
And applicationContext-comon.xml (common beans) (personal habits, you can not separate)
7, modify applicationContext-comon.xml have DTD
Amended to read:
<beans xmlns = " "
xmlns: xsi = " "
xmlns: aop = " "
xmlns: tx = " "
xsi: schemaLocation = "
">
Write back if this is more convenient to write
applicationContext-comon.xml final as follows:
<? xml version = "1.0" encoding = "UTF-8"?>
<beans xmlns = " "
xmlns: xsi = " "
xmlns: aop = " "
xmlns: tx = " "
xsi: schemaLocation = "
">
<! - Configuration of the part of the public ->
<! - Configuration sessionFactory ->
<bean
>
<property name = "configLocation"
value = "classpath: hibernate.cfg.xml">
</ property>
</ bean>
<! - Configure the transaction manager ->
<bean>
<property name="sessionFactory" ref="sessionFactory" />
</ bean>
<! - The spread of properties to configure Services ->
<tx:advice transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="merge" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</ tx: attributes>
</ tx: advice>
<! - Configuration AOP ->
<aop:config>
<! - Com.mengya.dao.imple in all categories, all categories of all the methods (.. that any form of parameters) are the starting point poincut ->
<aop:pointcut expression="execution(* com.mengya.dao.imple.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allMethod"/>
</ aop: config>
</ beans>
8, the action with Struts and actionForm
Hibernate in actionForm generated in the package Javabean
Modify struts-config.xml in the type of action will be com.mengya.struts.action.StuAction amended to: org.springframework.web.struts.DelegatingActionProxy
9, in the Spring of action in the Struts configuration
Struts in action change the type value: org.springframework.web.struts.DelegatingActionProxy (Acting)
<bean>
<property name="sessionFactory">
<ref bean="sessionFactory" />
</ property>
</ bean>
Note: DAO should inherit HibernateDaoSupport
<! - Struts configuration of the action, bean the name value for the action of the path ->
<bean name="/stu">
<property name="studao" ref="StudentDAO" />
</ bean>
10, configured in web.xml
<! - Using Spring to provide the encoding of the filter ->
<filter>
<filter-name> springfitler </ filter-name>
<filter-class> org.springframework.web.filter.CharacterEncodingFilter </ filter-class>
<init-param>
<param-name> encoding </ param-name>
<param-value> gbk </ param-value>
</ init-param>
</ filter>
<filter-mapping>
<filter-name> springfiter </ filter-name>
<url-pattern> / * </ url-pattern>
</ filter-mapping>
<! - If not in the web.xml to configure the following contents:
<context-param>
<param-name> contextConfigLocation </ param-name>
<param-value> classpath *: applicationContext-*. xml </ param-value>
</ context-param>
<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ listener>
->
Is coupled with the struts-config.xml
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="classpath*:applicationContext-*.xml"/>
</ plug-in>
11, well. OK, portfolio success!
Personal Note: After the collection may be wrong
1, may be less commons-pool-1.3.jar package (MyEclipse5.5)
2, may be necessary to re-build hibernate-annotations.jar package (MyEclipse5.1)








Responses to “Hibernate management Hibernate.cfg.xml by, Hibernate's session with the Tr”