解决方案 »
- hibernate复杂查询
- main方法为什么是静态的,说说大家的看法
- myeclise6.6调用C++的问题?
- 为什么会出现这样的错误:Unknown column 'aa' in 'field list'
- struts2 中通过pojo映射form出现空值
- struts+spring+hibernate整合Servlet action is not available错误
- 我想从Oracle官网下载JSF的jar包,不知道该下载哪个
- 关于用tomcat4.1和jboss3.0.1发布EJB(tomcat安装在一个机器上,jboss安装在别一个机器上)
- java rmi的入门问题
- 配置成功后马上结:用MS-dos运行java
- spring+struts+ibatis如何配置多数据源?
- 怎么在div中显示word中的图片
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager"/> 或者手动开启。
sessionfactory.getcurrentsession().beginTransaction()
sessionFactory.getCurrentSession().save(emp)
sessionfactory.getcurrentsession().endTransaction()
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
">
<context:component-scan base-package="com.xingao" />
<!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@192.168.0.249:1521:FIRST"/>
<property name="username" value="oauser"/>
<property name="password" value="xingaooa"/>
</bean>-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <property name="jdbcUrl"> <value>jdbc:oracle:thin:@192.168.0.249:1521:FIRST</value> </property> <property name="user"> <value>oauser</value> </property> <property name="password"> <value>xingaooa</value> </property> <!--连接池中保留的最小连接数。--> <property name="minPoolSize"> <value>3</value> </property> <!--连接池中保留的最大连接数。Default: 15 --> <property name="maxPoolSize"> <value>20</value> </property><!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 --> <property name="initialPoolSize"> <value>10</value> </property> <!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --> <property name="maxIdleTime"> <value>60</value> </property> <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --> <property name="acquireIncrement"> <value>5</value> </property> <!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0--> <property name="maxStatements"> <value>0</value>
</property>
<!--每60秒检查所有连接池中的空闲连接。Default: 0 --> <property name="idleConnectionTestPeriod"> <value>60</value> </property> <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30 --> <property name="acquireRetryAttempts"> <value>30</value> </property>
<!--获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效
保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试
获取连接失败后该数据源将申明已断开并永久关闭。Default: false--> <property name="breakAfterAcquireFailure"> <value>true</value> </property> <!--因性能消耗大请只在需要的时候使用它。如果设为true那么在每个connection提交的
时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable
等方法来提升连接测试的性能。Default: false --> <property name="testConnectionOnCheckout"> <value>false</value> </property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>com/xingao/entity/W_user.hbm.xml</value>
<value>com/xingao/entity/W_workschedule.hbm.xml</value>
<value>com/xingao/entity/T_role.hbm.xml</value>
<value>com/xingao/entity/T_connection.hbm.xml</value>
<value>com/xingao/entity/T_node_role.hbm.xml</value>
<value>com/xingao/entity/T_node.hbm.xml</value>
<value>com/xingao/entity/T_nodefile.hbm.xml</value>
<value>com/xingao/entity/T_role_user.hbm.xml</value>
<value>com/xingao/entity/T_select.hbm.xml</value>
<value>com/xingao/entity/T_template.hbm.xml</value>
<value>com/xingao/entity/T_templatefile.hbm.xml</value>
<value>com/xingao/entity/T_W_role_user.hbm.xml</value>
<value>com/xingao/entity/W_connection.hbm.xml</value>
<value>com/xingao/entity/W_node_role.hbm.xml</value>
<value>com/xingao/entity/W_node.hbm.xml</value>
<value>com/xingao/entity/W_nodefile.hbm.xml</value>
<value>com/xingao/entity/W_role_user.hbm.xml</value>
<value>com/xingao/entity/W_role.hbm.xml</value>
<value>com/xingao/entity/W_select.hbm.xml</value>
<value>com/xingao/entity/W_usertype.hbm.xml</value>
<value>com/xingao/entity/W_workflow.hbm.xml</value>
<value>com/xingao/entity/W_workflowdailyrecord.hbm.xml</value>
<value>com/xingao/entity/W_workflowfile.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hbm2ddl.auto">update</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="hibernate.connection.autocommit">true</prop>
</props>
</property>
</bean>
<!-- 以下为事务配置 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 使用基于注释式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="UserDaoImpl" class="com.xingao.dao.impl.UserDaoImpl"></bean>
<bean id="MyFlowDaoImpl" class="com.xingao.dao.impl.MyFlowDaoImpl"></bean>
<bean id="TemplateDaoImpl" class="com.xingao.dao.impl.TemplateDaoImpl"></bean>
<bean id="OurFlowDaoImpl" class="com.xingao.dao.impl.OurFlowDaoImpl"></bean>
<bean id="NodeDaoImpl" class="com.xingao.dao.impl.NodeDaoImpl"></bean>
<bean id="RoleDaoImpl" class="com.xingao.dao.impl.RoleDaoImpl"></bean>
<bean id="NodeRoleDaoImpl" class="com.xingao.dao.impl.NodeRoleDaoImpl"></bean>
<bean id="RoleUserDaoImpl" class="com.xingao.dao.impl.RoleUserDaoImpl"></bean>
<bean id="WNodeDaoImpl" class="com.xingao.dao.impl.WNodeDaoImpl"></bean>
<bean id="WRoleDaoImpl" class="com.xingao.dao.impl.WRoleDaoImpl"></bean>
<bean id="WWorkflowDaoImpl" class="com.xingao.dao.impl.WWorkflowDaoImpl"></bean>
<bean id="WNodeRoleDaoImpl" class="com.xingao.dao.impl.WNodeRoleDaoImpl"></bean>
<bean id="WRoleUserDaoImpl" class="com.xingao.dao.impl.WRoleUserDaoImpl"></bean>
<bean id="WConnectionDaoImpl" class="com.xingao.dao.impl.WConnectionDaoImpl"></bean>
<bean id="WSelectDaoImpl" class="com.xingao.dao.impl.WSelectDaoImpl"></bean>
<bean id="WWorkflowDailyRecordDaoImpl" class="com.xingao.dao.impl.WWorkflowDailyRecordDaoImpl"></bean>
<bean id="WWorkscheduleDaoImpl" class="com.xingao.dao.impl.WWorkscheduleDaoImpl"></bean>
<bean id="WWorkflowfileDaoImpl" class="com.xingao.dao.impl.WWorkflowfileDaoImpl"></bean>
<bean id="WNodeFileDaoImpl" class="com.xingao.dao.impl.WNodeFileDaoImpl"></bean>
</beans>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" propagation="NOT_SUPPORTED"
read-only="true" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor
pointcut="execution(* com.bysee.ssh2.service.*.*(..))"
advice-ref="txAdvice" />
</aop:config>
类似于这样写
java.lang.NoSuchMethodError: org.hibernate.engine.spi.SessionFactoryImplementor.getConnectionProvider()Lorg/hibernate/service/jdbc/connections/spi/ConnectionProvider
原因,在使用Spring3.2.x与Hibernate4.3.x(4.1.7以上)的版本整合时出的错。
解决方案:把Hibernate降至4.1.7或以下的版本就行了。
http://sourceforge.net/projects/hibernate/files/hibernate4/这是由Spring和Hibernate4.3.x版本兼容性的问题产生的
它的官方有如下说明:
https://jira.springsource.org/browse/SPR-10839如果你不想改变也可以,自己改一下它的原码就行了。相当于一个补丁吧。
1、把你想下载的Hibernate(4.3.0或以上)拷到你的项目中去。
2、从org.springframework.orm.hibernate4包中的源码拷到你自己的项目包中来,如:com.my.hibernate4.spring.fix: HibernateTransactionManager, SessionFactoryUtils, SpringFlushSynchronization, SpringSessionContext 和 SpringSessionSynchronization.
3、改变导入SpringSessionContext类的JtaPlatform 从 org.hibernate.service.jta.platform.spi.JtaPlatform 改为 org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform
4、改变导入SessionFactoryUtils类的ConnectionProvider 从 org.hibernate.service.jdbc.connections.spi.ConnectionProvider 改为 org.hibernate.engine.jdbc.connections.spi.ConnectionProvider
5、解决它们报的那些包名错误及其他的一些错误。
6、在Spring配置文件中配置时如下:
1
2
3
<bean id="transactionManager" class="com.my.hibernate4.spring.fix.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
本人亲测,换到hibernate4.1.7,问题解决。