ssh整合问题
我前面整合的spring3+struts2+hibernate4.由于要使用jbpm4,所以hibernate要换成3.
这是spring配置文件
<!--开启注解处理器-->
<context:annotation-config/>
<!--扫描包路径-->
<context:component-scanbase-package="com.eport"/>
<!--加载jdbc.properties文件-->
<context:property-placeholderlocation="classpath:jdbc.properties"/>
<!--配置数据源-->
<beanid="dataSource"class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<propertyname="driverClass"value="${driverClassName}"/>
<propertyname="jdbcUrl"value="${jdbcUrl}"/>
<propertyname="user"value="${user}"/>
<propertyname="password"value="${password}"/>
<propertyname="minPoolSize"value="1"/>
<propertyname="maxPoolSize"value="10"/>
<propertyname="initialPoolSize"value="1"/>
<propertyname="acquireIncrement"value="1"/>
<propertyname="acquireRetryAttempts"value="3"/>
<propertyname="maxIdleTime"value="3600"/>
</bean>
<!--整合hibernate-->
<beanid="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<propertyname="configLocation"value="classpath:hibernate.cfg.xml"/>
<propertyname="dataSource"ref="dataSource"/>
<propertyname="mappingLocations">
<list>
<value>classpath:jbpm.execution.hbm.xml</value>
<value>classpath:jbpm.history.hbm.xml</value>
<value>classpath:jbpm.identity.hbm.xml</value>
<value>classpath:jbpm.repository.hbm.xml</value>
<value>classpath:jbpm.task.hbm.xml</value>
</list>
</property>
</bean>
<!--配置jBPM的流程引擎-->
<beanid="springHelper"class="org.jbpm.pvm.internal.processengine.SpringHelper">
<propertyname="jbpmCfg"value="jbpm.cfg.xml"/>
</bean>
<beanid="processEngine"factory-bean="springHelper"factory-method="createProcessEngine"/>
<beanid="repositoryService"factory-bean="processEngine"factory-method="getRepositoryService"/>
<beanid="executionService"factory-bean="processEngine"factory-method="getExecutionService"/>
<beanid="taskService"factory-bean="processEngine"factory-method="getTaskService"/>
<beanid="historyService"factory-bean="processEngine"factory-method="getHistoryService"/>
<beanid="identityService"factory-bean="processEngine"factory-method="getIdentityService"/>
<!--配置事务管理器-->
<beanid="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<propertyname="sessionFactory"ref="sessionFactory"/>
</bean>
<tx:annotation-driventransaction-manager="transactionManager"/>
这是hibernate配置文件
<hibernate-configuration>
<session-factory>
<propertyname="dialect">org.hibernate.dialect.SQLServerDialect</property>
<propertyname="show_sql">false</property>
<propertyname="format_sql">true</property>
<propertyname="hbm2ddl.auto">update</property>
<propertyname="current_session_context_class">
org.springframework.orm.hibernate3.SpringSessionContext
</property>
<mappingclass="com.eport.account.pojo.Account"/>
<mappingclass="com.eport.account.pojo.PrivilegeGroup"/>
<mappingclass="com.eport.account.pojo.SystemPrivilege"/>
</session-factory>
</hibernate-configuration>
这是dao配置文件
@Transactional
publicclassDaoSupport<T>implementsDao<T>{
@Resource(name="sessionFactory")
protectedSessionFactorysessionFactory;
privatefinalClass<T>entityClass;
@SuppressWarnings("unchecked")
publicDaoSupport(){
this.entityClass=(Class<T>)((ParameterizedType)getClass().
getGenericSuperclass()).getActualTypeArguments()[0];
}
publicSessiongetSession(){
returnsessionFactory.getCurrentSession();
}
@Override
publiclonggetCount(){
Queryquery=this.getSession().createQuery("selectcount("+
DaoSupport.getCountField(this.entityClass)+")from"+
this.buildEntityName()+"o");
returnnewLong(query.uniqueResult().toString()).longValue();
}
@Override
publicvoiddelete(Tentity){
this.getSession().delete(entity);
}
@Override
publicvoidsave(Tentity){
this.getSession().save(entity);
}
@Override
publicvoidupdate(Tentity){
this.getSession().update(entity);
}
@SuppressWarnings("unchecked")
@Override
@Transactional(propagation=Propagation.REQUIRED)
publicTfind(Serializableid){
return(T)getSession().get(this.entityClass,id);
}
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
publicQueryResult<T>getScrollData(intstartIndex,intmaxresult,
Stringjpql,Object[]params){
returnthis.getScrollData(startIndex,maxresult,jpql,params,null);
}
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
publicQueryResult<T>getScrollData(intstartIndex,intmaxresult,
LinkedHashMap<String,String>orderby){
returnthis.getScrollData(startIndex,maxresult,null,null,orderby);
}
publicQueryResult<T>getScrollData(Stringjpql,Object[]params,
LinkedHashMap<String,String>orderby){
returnthis.getScrollData(-1,-1,jpql,params,orderby);
}
@SuppressWarnings({"unchecked","static-access"})
publicQueryResult<T>getScrollData(intstartIndex,intmaxresult,
Stringjpql,Object[]params,LinkedHashMap<String,String>orderby){
QueryResult<T>qr=newQueryResult<T>();
StringentityName=buildEntityName();
StringwhereJpql="";
if(jpql!=null&&!"".equals(jpql)){
whereJpql="where"+jpql;
}
Queryquery=this.getSession().createQuery("selectofrom"+entityName+
"o"+whereJpql+methodOrderby(orderby));
if(jpql!=null&&!"".equals(jpql)){
this.setParms(query,params);
}
if(startIndex!=-1&&maxresult!=-1){//只有这两个参数都不等于-1,才进行分页
query.setFirstResult(startIndex);
query.setMaxResults(maxresult);
}
qr.setResultList(query.list());
//统计查询记录数
query=this.getSession().createQuery("selectcount("+
this.getCountField(this.entityClass)+")from"+entityName+"o"
+whereJpql);
if(jpql!=null&&!"".equals(jpql)){
this.setParms(query,params);
}
qr.setTotalrecords(newLong(query.uniqueResult().toString()).longValue());
returnqr;
}
@Transactional(readOnly=true,propagation=Propagation.NOT_SUPPORTED)
publicQueryResult<T>getScrollData(){
returnthis.getScrollData(-1,-1,null,null,null);
}
@Override
publicvoidflush(){
this.getSession().flush();
}
@Override
publicvoidclear(){
this.getSession().clear();
}
privateStringmethodOrderby(LinkedHashMap<String,String>orderby){
StringBuildersb=newStringBuilder();
if(orderby!=null&&orderby.size()>0){
sb.append("orderby");
for(Stringkey:orderby.keySet()){
sb.append("o.").append(key).append("").append(orderby.get(key)).append(",");
}
sb.deleteCharAt(sb.length()-1);//删除最后多余的逗号
}
returnsb.toString();
}
/**
*对query对象进行参数赋值
*
*@paramquery
*@paramparams
*/
privatevoidsetParms(Queryquery,Object[]params){
if(params!=null&¶ms.length>0){
for(inti=0;i<params.length;i++){
query.setParameter(i,params[i]);
}
}
}
/**
*通过实体clazz对象,构建查询的实体名字
*
*@return
*/
privateStringbuildEntityName(){
Stringname=entityClass.getSimpleName();
Entityentity=entityClass.getAnnotation(Entity.class);
if(entity.name()!=null&&!"".equals(entity.name().trim())){
name=entity.name();
}
returnname;
}
protectedstatic<E>StringgetCountField(Class<E>clazz){
Stringout="o";
try{
PropertyDescriptor[]propertyDescriptors=Introspector.getBeanInfo(clazz).getPropertyDescriptors();
for(PropertyDescriptorpropertydesc:propertyDescriptors){
Methodmethod=propertydesc.getReadMethod();
if(method!=null&&method.isAnnotationPresent(EmbeddedId.class)){
PropertyDescriptor[]ps=Introspector.getBeanInfo(propertydesc.getPropertyType())
.getPropertyDescriptors();
out="o."+propertydesc.getName()+"."
+(!ps[1].getName().equals("class")?ps[1].getName():ps[0].getName());
break;
}
}
}catch(Exceptione){
e.printStackTrace();
}
returnout;
}
}
但是我在运行的时候报了错误
java.lang.ClassCastException:org.springframework.orm.hibernate4.SessionHoldercannotbecasttoorg.springframework.orm.hibernate3.SessionHolder
hibernate4.SessionHolder不能转换为hibernate3.SessionHolder。但是我都改成hibernate3
了啊。不知道这个hibernate4是哪里来的