-
Jan 3rd, 2009, 10:27 PM
#1
how can i config spring +hibernate + proxool + jpa ?
hi everyone,
i have encounting a problems on config spring2.5.6 hibernate3.3 proxool-0.9.1.jar jpa,
i only use jpa to instead of *.hbm.xml to mapping entities.
but i could see any transaction info in log4j output( i have turn on debug mode) ,and the transaction did't work!
and even i could't see any dynamic proxy info which create by spring aop via cglib
when i throw a Exception which is RuntimeException's subclass,
hibernate did't rollback
my config file as below
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns
="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"
default-autowire="byName">
<context:annotation-config />
<context:component-scan base-package="com.xx">
</context:component-scan>
<bean class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<!--
<ref bean="openSessionInViewInterceptor"/>
-->
<ref bean="authorizeInterceptor"/>
</list>
</property>
</bean>
<!--
<bean id="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support. OpenSessionInViewInterceptor">
<property name="flushModeName">
<value>FLUSH_AUTO</value>
</property>
<property name="sessionFactory" ref="sessionFactory" />
</bean>
-->
<bean class="org.springframework.web.servlet.mvc.annotat ion.AnnotationMethodHandlerAdapter">
<property name="cacheSeconds" value="2" />
<property name="webBindingInitializer">
<bean class="com.xx.controller.BindingInitializer" />
</property>
</bean>
<bean id="velocityConfig" class="org.springframework.web.servlet.view.veloci ty.VelocityConfigurer">
<property name="resourceLoaderPath" value="/vm/"></property>
<property name="velocityProperties">
<props>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding">UTF-8</prop>
<prop key="contentType">text/html;charset=UTF-8</prop>
<prop key="file.resource.loader.cache">false</prop>
<prop key="file.resource.loader.modificationCheckInterva l">2</prop>
<prop key="velocimacro.library.autoreload">true</prop>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.veloci ty.VelocityViewResolver">
<property name="cache" value="true" />
<property name="prefix" value="" />
<property name="suffix" value=".vm" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="contentType" value="text/html;charset=UTF-8" />
<property name="dateToolAttribute" value="dateTool"></property>
<property name="numberToolAttribute" value="numberTool"></property>
<property name="exposeRequestAttributes" value="true"></property>
<property name="exposeSessionAttributes" value="true"></property>
<property name="toolboxConfigLocation" value="WEB-INF/classes/toolbox.xml"></property>
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.C ommonsMultipartResolver">
<property name="maxUploadSize">
<value>50000000</value>
</property>
<property name="maxInMemorySize">
<value>4096</value>
</property>
</bean>
</beans>
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns
="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd"
default-autowire="byName">
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotati on.AnnotationSessionFactoryBean">
<property name="packagesToScan">
<list>
<value>com.x.domain</value>
</list>
</property>
<property name="configLocation">
<value>WEB-INF/classes/hibernate.cfg.xml</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.xx.service.*.*(..))"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager" >
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="REQUIRED"/>
<tx:method name="select*" read-only="true" propagation="REQUIRED"/>
<tx:method name="find*" read-only="true" propagation="REQUIRED"/>
<tx:method name="load" read-only="true" propagation="REQUIRED"/>
<tx:method name="query" read-only="true" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED" isolation="READ_COMMITTED" />
<tx:method name="insert*" propagation="REQUIRED" isolation="READ_COMMITTED" />
<tx:method name="create" propagation="REQUIRED" isolation="READ_COMMITTED" />
<tx:method name="save*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<tx:method name="update*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<tx:method name="delete*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<tx:method name="remove*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
<tx:method name="test*" propagation="REQUIRED" isolation="READ_COMMITTED"/>
</tx:attributes>
</tx:advice>
</beans>
Last edited by ilysony; Jan 3rd, 2009 at 10:40 PM.
-
Jan 4th, 2009, 02:00 AM
#2
Java code
@Repository
public class BaseHibernateDao extends HibernateDaoSupport {
}
SERVICE
Java code
@Service
public class TestService extends BaseService {
@Autowired
TestDao testDao;
public void testTT(){
testDao.testTT();
}
}
DAO
Java code
@Service
public class TestDAO extends BaseHibernateDao{
public void testTT(){
String hql = " update Test set age= ? where id = 1000 ";
Query q = this.getSession(true).createQuery(hql);
q.setInteger(0, 3333333);
q.executeUpdate();
Test n = new Test();
n.setAddtime( new Date() );
n.age( new Long(101) );
n.setDatastr("22222222222");
n.setPid( Long.parseLong("sssssssssssss") );
//此处故意throw RuntimeException子类
session.save(n);
//not rollback?
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules