<!--loading hibernate.properties files--><bean id= "Propertyconfig" class= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer "><property name=" Locations "> <value>/WEB-INF/jdbc.properties</value> </property></bean>
JDBC Connection Configuration
<bean id= "DataSource" class= " Org.springframework.jdbc.datasource.DriverManagerDataSource "><property name=" Driverclassname "value=" Com.mysql.jdbc.Driver "></property><property name=" url "value=" Jdbc:mysql://localhost:3306/test "> </property><property name= "username" value= "root" ></property><property name= "password" value= "Root" ></property></bean><bean id= "sessionfactory" class= " Org.springframework.orm.hibernate4.LocalSessionFactoryBean "><property name=" DataSource "ref=" DataSource " ></property><property name= "hibernateproperties" ><props><prop key= "Hibernate.dialect" >org.hibernate.dialect.mysqldialect</prop><prop key= "Hibernate.show_sql" >true</prop></ Props></property><property name= "Mappingresources" ><list><value>com/ssh/bean/ Person.hbm.xml</value></list></property></bean>
connection Pool configuration:
<!--c3p0 Connection pool--><bean id= "DataSource" class= "Com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method= " Close "><property name=" Driverclass "><value>${hibernate.connection.driver_class}</value> </property><property name= "Jdbcurl" ><value>${hibernate.connection.url}</value></ Property><property name= "User" > <value>${hibernate.connection.username}</value></ Property><property name= "Password" ><value>${hibernate.connection.password}</value></ property><!--The minimum number of connections that are kept in the connection pool. --><property name= "Minpoolsize" ><value>5</value></property><!--the maximum number of connections that are kept in the connection pool. Default:15--><property name= "maxpoolsize" > <value>100</value></property><!-- The number of connections obtained at initialization, and the value should be between Minpoolsize and Maxpoolsize. Default:3--><property name= "initialpoolsize" > <value>5</value></property><!-- Maximum idle time, unused in 60 seconds, the connection is discarded. If 0, it will never be discarded. default:0--><property Name= "MaxIdleTime" > <value>60</value></property><!--when the connection in the connection pool is exhausted c3p0 the number of simultaneous connections that are obtained at the same time. Default:3--><property name= "acquireincrement" > <value>3</value></property><!-- The standard parameters of JDBC to control the number of preparedstatements loaded within the data source. However, because the pre-cached statements belong to a single connection instead of the entire connection pool. So setting this parameter takes into account a variety of factors. If both maxstatements and maxstatementsperconnection are 0, the cache is closed. default:0--><property name= "maxstatements" ><value>0</value></property><!-- Check for idle connections in all connection pools every 60 seconds. default:0--><property name= "Idleconnectiontestperiod" ><value>60</value></property> <!--defines the number of times to try repeatedly after a new connection has failed from the database. default:30--><property name= "acquireretryattempts" ><value>30</value></property><! --Getting a connection failure will cause all the threads waiting for the connection to pools to throw an exception. However, the data source is still valid and continues to try to get the connection the next time you call Getconnection (). If set to True, the data source will declare broken and permanently shut down after attempting to obtain a connection failure. Default:false--><property name= "Breakafteracquirefailure" ><value>true</value></property ><!--for sexCan consume large please use it only when you need it. If set to true then officer the validity of each connection submission. We recommend using methods such as Idleconnectiontestperiod or automatictesttable to improve the performance of your connectivity tests. Default:false--><property name= "Testconnectiononcheckout" ><value>false</value></ Property></bean>
<!--create Sessionfactory--><bean id= "Sessionfactory" class= " Org.springframework.orm.hibernate3.LocalSessionFactoryBean "> <property name=" dataSource "ref=" DataSource " ></property>
<!--config Hibernate Field--<property name= "hibernateproperties" ><props><prop key= "hibernate . dialect "> ${hibernate.dialect}</prop><prop key=" hibernate.generate_statistics ">true</prop> <prop key= "Hibernate.jdbc.fetch_size" > ${hibernate.jdbc.fetch_size}</prop><prop key= " Hibernate.jdbc.batch_size "> ${hibernate.jdbc.batch_size}</prop> <prop key=" Hibernate.current_se Ssion_context_class ">thread</prop> <prop key=" Hibernate.bytecode.use_reflection_optimizer ">f alse</prop> <prop key= "hibernate.query.substitutions" >true</prop> <prop key= "Hibernate.show_sql" >${hibernate.show_sql}</prop> <prop key= "Hibernate.max_fetch_depth" ;3</prop> <prop key= "Hibernate.hibernate.use_outer_join" >true</prop> < ;p rop key= "Hibernate.jdbc.batch_size" >50</prop> <!--prop key= "Hibernate.cache.use_query_cache" >${hibernate.cache.use_query_cache}< /prop> <prop key= "Hibernate.cache.use_second_level_cache" >true</prop> <prop key= "Hibernate.cache.provider_class" >${hibernate.cache.provider_class}& Lt;/prop-<!--automatically add new tables, execute the command when you restart the service, make sure to annotate this sentence (native use) and <!-- Prop key= "Hibernate.hbm2ddl.auto" >update</prop--></props> </property> <!--mapping Hibernate model PO class--> <property name= "mappingdirectorylocations" ><list> <value>/web-inf/ classes/com/cms/pojo</value><!--Change all the profiles under Folders--></list> </property>
</bean>
Transaction Configuration Method One:
<!--define transaction manager--><bean id= "TransactionManager" class= " Org.springframework.orm.hibernate4.HibernateTransactionManager "><property name=" sessionfactory "ref=" Sessionfactory "></property></bean><bean id=" Transactioninterceptor "class=" Org.springframework.transaction.interceptor.TransactionInterceptor "><!--configuration transaction manager--><property Name=" TransactionManager "ref=" TransactionManager "></property><!--Configure transaction properties--><property name=" Transactionattributes "><props><prop key=" * ">propagation_required</prop></props></ Property></bean><bean class= "Org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" ><property name= "Beannames" ><list><value>persondaoimpl</value></list></ Property><property name= "Interceptornames" ><list><value>transactioninterceptor</value ></list></property></bean>
transaction Configuration method two:
<!--config transaction manager--><bean id= "TransactionManager" class= " Org.springframework.orm.hibernate3.HibernateTransactionManager "><property name=" sessionfactory "ref=" Sessionfactory "></property></bean> <!--transactional advice-- <tx:advice id=" Txadvice "transaction-manager=" TransactionManager "> <tx:attributes> <tx:method name=" save* "/ ><tx:method name= "update*"/><tx:method name= "delete*"/><tx:method name= "Add"/><tx:method Name= "modify*"/><tx:method name= "remove*"/><tx:method name= "merge*"/><!--<tx:method name= " list* "/>--><!--<tx:method name=" ajax* "/>- <!--other methods is set to read only-->
<!--tx:method name= "*" read-only= "true"/- </tx:attributes> </tx:advice>
Applicationcontext.xml Important Configuration