What is wrong with my Spring Hibernate Transaction Management Configuration? -


i using spring 2.5.5. hibernate3.2. , mysql.
getting:

org.hibernate.lazyinitializationexception: not initialize proxy - no session  @ org.hibernate.proxy.abstractlazyinitializer.initialize(abstractlazyinitializer.java:57)  @ org.hibernate.proxy.abstractlazyinitializer.getimplementation(abstractlazyinitializer.java:111)  @ org.hibernate.proxy.pojo.cglib.cgliblazyinitializer.invoke(cgliblazyinitializer.java:150)  @ beans.country$$enhancerbycglib$$e757f40e.getstringid(<generated>)  @ beans.address.getcountrystringid(address.java:137)  @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)  @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source)  @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)  @ java.lang.reflect.method.invoke(unknown source)  @ org.hibernate.proxy.pojo.cglib.cgliblazyinitializer.invoke(cgliblazyinitializer.java:157)  @ beans.address$$enhancerbycglib$$ef3e9848.getcountrystringid(<generated>)  @ checkout.orderservice.ecsetexpresscheckoutcode(orderservice.java:274) 

this part understand (hibernate put proxy address instead of real target , when try address persisted user object in checkout.orderservice.ecsetexpresscheckoutcode method lazyinitializationexception).

that why started reading transaction management spring , hibernate. read couple of threads @ stackoverflow haven't encountered implementation. read also:
http://community.jboss.org/wiki/sessionsandtransactions
http://community.jboss.org/wiki/opensessioninview
http://community.jboss.org/wiki/sessionhandlingwithaop
spring reference - 9.5. declarative transaction management
spring reference - 12.2.7. declarative transaction demarcation
, more.
transaction management configuration (following instructions) looks this:

 <!-- =============================== transaction managment ============================= -->  <!-- transactional advice (what 'happens'; see <aop:advisor/> bean below) -->  <tx:advice id="txadvice" transaction-manager="txmanager">   <!-- transactional semantics... -->   <tx:attributes>    <!-- methods starting 'get' read-only -->    <tx:method name="get*" read-only="true"/>    <!-- other methods use default transaction settings (see below) -->    <tx:method name="*"/>   </tx:attributes>  </tx:advice>   <aop:config>   <aop:pointcut id="orderserviceoperation" expression="execution(* checkout.orderservice.*(..))"/>   <aop:advisor advice-ref="txadvice" pointcut-ref="orderserviceoperation"/>  </aop:config>  <bean id="txmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager">   <property name="sessionfactory">               <ref local="sessionfactory"/>   </property>  </bean>  <!-- ============================ end of transaction managment ========================= --> 

i same error again!
not sure if configuration collides dao layer implementation have (but shouldn't supposed to):

public class accountdao implements accountdaointerface {   private hibernatetemplate hibernatetemplate;   public void setsessionfactory(sessionfactory sessionfactory) {   this.hibernatetemplate = new hibernatetemplate(sessionfactory);  }   public user getuserforuserid(final long ruserid)  throws dataaccessexception {   return (user) this.hibernatetemplate.execute(new hibernatecallback() {    public object doinhibernate(session session) {     list objlist = session.createquery("from user id=" + userid).list();     user user = null;     if (!objlist.isempty()){      user = (user) objlist.get(0);     }     return user;    }   });  }   //other methods  } 

i understand address proxy "real" target db, need provide hibernate session , transaction. there several patterns read, convenient me declarative approach leaving methods demarcated ("clean" transaction logic). so miss in config? remember not need transaction management in dao layer service layer (and maybe controllers). how can make work?

kind regards,
despot

edit1: (due request more info) first of @ accountdao, method getuserforuserid. this method call 1 point of application. can understand user , how mapped, provide following pojos:

public class user implements serializable{     private long id;     private address shippingaddress;     private address billingaddress;     private string otherdata;     //default constructor, constructor using fields, getters, setters. } public class address implements serializable{     private long id;     private country country;     private string otherdata;     //default constructor, constructor using fields, getters, setters. } public class country implements serializable {     int id;     string stringid;     string name; } 

and mapping files:

<class name="user" table="user">     <id name="id" column="id" type="long" unsaved-value="-1">         <generator class="native" />     </id>     <many-to-one name="shippingaddress" class="beans.address" column="shippingaddressid" not-null="true" cascade="persist,merge,save-update"/>     <many-to-one name="billingaddress" class="beans.address" column="billingaddressid" not-null="true" cascade="persist,merge,save-update"/> </class> <class name="address" table="address">     <id name="id" column="id" type="long">         <generator class="native" />     </id>     <many-to-one name="country" class="country" column="countryid" not-null="true" cascade="none"  /> </class> <class name="country" table="country">     <id name="id" column="id" type="integer">         <generator class="native" />     </id>     <property name="stringid" type="string" not-null="true" length="4"/>     <property name="name" type="string" not-null="true" length="100"/> </class> 

after user in 1 point of application, processing flows ok since don't access address in user object. imagine couple of requests , responses go , forth. request comes along (not important but, user chooses option , clicks on submit button) , processing leads checkout.orderservice.ecsetexpresscheckoutcode method @ line orderservice.java:274 have:

user.getshippingaddress().getcountrystringid().equals(addressconst.country_us_string_id) 

once try enter line lazyinitexception, since address class mapped default lazy="true" attribute.
enough explanation? the question correct spring hibernate declarative transaction management configuration?

are retrieving country object db in 1 call orderservice , trying access in call orderservice? think can use proxies long maintain same session.

anyway should provide complete code.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -