Integration of Spring Learning notes Hibernate

Source: Internet
Author: User

1, Web. XML inside to configure the corresponding Springxml path

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>

Conf/kernel/spring_kernel/spring-*.xml,

Conf/business/spring_business/spring-*.xml,

Conf/custom/spring_custom/spring-*.xml

</param-value>

</context-param>

2, the corresponding folder inside to have Spring-hibernate.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:p=" http://www.springframework.org/schema/p "xsi:schemalocation="/HTTP/ Www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd ">

<bean id= "Defaultlobhandler" class= "Org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init= "true" ></bean>

<bean id= "DataSource" class= "Org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy" >
<property name= "Targetdatasource" >
<bean class= "com.**********. Datasourcefactorybean ">
<property name= "Propertypool" value= "**************"/>
<property name= "Propertyprefix" value= "***************."/>
</bean>
</property>
</bean>

<!--session Factory-start-to-
<bean id= "Sessionfactory" class= "com.**********. Localsessionfactorybean ">
<property name= "DataSource" ref= "DataSource"/>
<property name= "Mappingdirectorylocations" >
<list>
<value>classpath*:conf/kernel/hibernate_kernel/**/*.hbm.xml</value>
<value>classpath*:conf/business/hibernate_business/**/*.hbm.xml</value>
<value>classpath*:conf/custom/hibernate_custom/**/*.hbm.xml</value>
</list>
</property>
<property name= "Lobhandler" ref= "Defaultlobhandler" ></property>
</bean>


<!--claims Spring transaction management-Start-
<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
<property name= "Sessionfactory" ref= "Sessionfactory"/>
</bean>

<!--Spring_jdbc-start--
<bean id= "JdbcTemplate" class= "Org.springframework.jdbc.core.JdbcTemplate" >
<property name= "DataSource" >
<ref bean= "DataSource"/>
</property>
</bean>

<!--spring transaction propagation mechanism-start-to-
<bean id= "Txproxytemplate" abstract= "true" class= " Org.springframework.transaction.interceptor.TransactionProxyFactoryBean ">
<property name= "TransactionManager" >
<ref bean= "TransactionManager"/>
</property>
<property name= "Proxytargetclass" >
<value>true</value><!--Specifies to proxy the class directly, specifying the property Proxytargetclass as True (default is False, proxy to the interface)-
</property>
<property name= "Transactionattributes" >
<props>
<prop key= "get*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "query*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "find*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "load*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "inquery*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "inquiry*" >PROPAGATION_REQUIRED,readOnly</prop>
<prop key= "validate*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "delete*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "remove*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "save*" >propagation_required,-java.lang.exception,-org.springframework.dao.dataaccessexception </prop>
<prop key= "add*" >propagation_required,-java.lang.exception,-org.springframework.dao.dataaccessexception </prop>
<prop key= "process*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "insert*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "create*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "update*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "modify*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "persist*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "driven*" >propagation_required,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "parse*" >propagation_required,-java.lang.exception,-org.springframework.dao.dataaccessexception </prop>
<prop key= "middleupdate*" >propagation_requires_new,-java.lang.exception,- Org.springframework.dao.dataaccessexception</prop>
<prop key= "*" >propagation_required,-java.lang.exception,-org.springframework.dao.dataaccessexception</ Prop>
</props>
</property>
</bean>

<bean id= "Dynamicbeanreader" class= "com.***********. Dynamicbeanreader "init-method=" init ">
</bean>

</beans>

3.

LOB (large object) is a type of data that is used to store large objects, such as medical records (such as x-rays), video, images, and so on. There are three types of lobs: Blob:binary Large object, Clob:character Large object, Dbclob:double-byte Character Large object. Each LOB can have 2GB.

4, Dynamicbeanreader:bean dynamic loading interface. It is used to dynamically load beans during running, such as dynamic loading of data sources, dynamic loading of timed tasks, etc.

5, in most cases, the transaction properties of each transaction agent are the same, the implementation class of the transaction agent is Transactionproxyfactorybean, and the transaction agent Bean must inject the transaction manager. In this case, spring provides inheritance between beans and beans to simplify configuration. The majority of the common configuration is configured as a transaction template, and the actual transaction proxy Bean inherits the transaction template. This configuration can reduce some of the configuration code, compared to the previous direct use of Transactionproxyfactorybean transaction proxy configuration, can greatly reduce the amount of code in the configuration file. The configuration of each transaction agent inherits the transaction template, eliminating the need to repeatedly specify the transaction broker's implementation class, without repeating the transaction propagation properties--of course, if the new transaction agent has additional transaction properties, it can also specify its own transaction properties, at which point the properties of the child bean override the parent bean's properties. Of course each transaction agent Bean must be configured with its own target bean, which is unavoidable. As the above configuration shows, the configuration of the transaction agent is still incremental, and each transaction agent needs to be configured separately-although the increment has been reduced, each transaction agent needs to be configured separately.

The value in <prop> in the spring configuration above is the transaction attribute information, the matching format is: propagation (propagation behavior), Isolation (Isolation level (optional)), readOnly (whether it is a read-only transaction (optional)),- Exceptions (option to roll back the transaction if these exceptions occur), +exceptions (optionally, commit the transaction if these exceptions occur)

6, spring default is to use the C3P0

Integration of Spring Learning notes Hibernate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.