java - Hibernate transaction begin and commit at the right point -


i have dao package daoclasses implements amongst others following methode:

public class xdaoimpl implements xdao {      private sessionfactory sessionfactory;      public void setsessionfactory(sessionfactory sessionfactory) {         this.sessionfactory = sessionfactory;     }      public sessionfactory getsessionfactory() {         return sessionfactory;     }      @override     public void saveorupdate(myobject o) {             //transaction trans = getsessionfactory().getcurrentsession().begintransaction();             getsessionfactory().getcurrentsession().saveorupdate(o);              //trans.commit();         } } 

if run application needs lot time store objects database. belief happens because create new transaction each object. tried use spring framework’s xml based declarative transaction implementation. till not work me:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xmlns:tx="http://www.springframework.org/schema/tx"      xmlns:aop="http://www.springframework.org/schema/aop"     xsi:schemalocation="http://www.springframework.org/schema/beans                            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd                            http://www.springframework.org/schema/tx                            http://www.springframework.org/schema/tx/spring-tx.xsd                            http://www.springframework.org/schema/aop                            http://www.springframework.org/schema/aop/spring-aop.xsd">      <bean class="org.springframework.beans.factory.config.propertyplaceholderconfigurer">         <property name="location">             <value>/resources/spring/config/database.properties</value>         </property>     </bean>       <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource">         <property name="driverclassname" value="${jdbc.driverclassname}" />         <property name="url" value="${jdbc.url}" />         <property name="username" value="${jdbc.username}" />         <property name="password" value="${jdbc.password}" />     </bean>       <bean id="hibernate3sessionfactory" class="org.springframework.orm.hibernate3.localsessionfactorybean">          <property name="datasource" ref="datasource" />          <property name="mappingresources">             <list>                 <value>/resources/spring/config/a.hbm.xml</value>                 <value>/resources/spring/config/b.hbm.xml</value>                 <value>/resources/spring/config/c.hbm.xml</value>                 <value>/resources/spring/config/d.hbm.xml</value>             </list>         </property>          <property name="hibernateproperties">             <props>                 <prop key="hibernate.dialect">org.hibernate.dialect.postgresqldialect</prop>                 <prop key="hibernate.current_session_context_class">thread</prop>                 <prop key="hibernate.hbm2ddl.auto">create</prop>                 <prop key="hibernate.show_sql">true</prop>             </props>         </property>      </bean>      <bean id="dbo" class="com.model.bo.dboimpl">         <property name="ddao" ref="ddao" />         <property name="bdao" ref="bdao" />     </bean>      <bean id="ddao" class="com.model.dao.ddaoimpl">         <property name="sessionfactory" ref="hibernate3sessionfactory" />     </bean>      <bean id="abo" class="com.model.bo.aboimpl">         <property name="adao" ref="adao" />         <property name="bdao" ref="bdao" />         <property name="cdao" ref="cdao" />     </bean>      <bean id="bdao" class="com.model.dao.bdaoimpl">         <property name="sessionfactory" ref="hibernate3sessionfactory" />     </bean>      <bean id="cdao" class="com.model.dao.cdaoimpl">         <property name="sessionfactory" ref="hibernate3sessionfactory" />     </bean>     <bean id="adao" class="com.model.dao.adaoimpl">         <property name="sessionfactory" ref="hibernate3sessionfactory" />     </bean>       <bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager">         <property name="sessionfactory" ref="hibernate3sessionfactory" />     </bean>     <tx:advice id="txadvice" transaction-manager="transactionmanager">         <tx:attributes>             <tx:method name="get*" read-only="true" />             <tx:method name="*" propagation="required" />         </tx:attributes>     </tx:advice>     <aop:config>         <aop:pointcut id="bomethods" expression="execution(* com.model.bo.*.*(..))" />          <aop:advisor advice-ref="txadvice" pointcut-ref="bomethods" />     </aop:config>      </beans> 

the error thrown:

class org.springframework.beans.factory.beancreationexception error creating bean name 'datasource' defined in class path resource [resources/spring/config/beanlocations.xml]: beanpostprocessor before instantiation of bean failed; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'org.springframework.aop.support.defaultbeanfactorypointcutadvisor#0': cannot resolve reference bean 'bomethods' while setting bean property 'pointcut'; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'bomethods': instantiation of bean failed; nested exception java.lang.noclassdeffounderror: org/aspectj/weaver/bcexception

public class dboimpl implements dbo {      private ddao ddao;     private bdao bdao;       public ddao getddao() {         return ddao;     }      public void setddao(ddao ddao) {         this.ddao = ddao;     }      public bdao getbdao() {         return bdao;     }      public void setbdao(bdao bdao) {         this.bdao = bdao;     }  public d add(d r) {         ddao.saveorupdate(r);         return r;     }  } 

it looks don't have aop jar files in class path.

see: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html

look section "10.2.1 enabling @aspectj support"


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -