mathiasberg
May 9th, 2008, 02:49 AM
The thing im wondering about is, when does the transaction start and end (commit) for my web app, when doing a update?
Im using JSF1.1, Spring 2.0.8 and Hibernate 3.2.6.ga.
Example flow of a list and update page (Both on the same page).
1. User clicks save from a JSF page,
2. JSF Bean then execute a Service method. (This method is marked as @Transactional)
3. Service updates through DAO layer the hibernate object from the update page.
4. Service method return back to JSF BEAN (Is the transaction finish now, should there be a commit now?)
5. JSF Bean re-load the list of Hibernate objects to be presented on the page. (The newly updated Hibernate object should exist here, right?)
6. Return to the same JSF page. Showing the list of objects with the newly updated object.
Problem here for me is that the List of objects (5) doesnt contain the newly updated object (Done in 3). Instead the old object is loaded into the list.
Home come? if i reload the page, then the list will exist with the newly updated object value.
Could it be that the transaction doens't end until JSF page is reach and until then i cant refresh my hibernate list with the new object values?
If so, can i commit my changes just before i end the Service method (3) instead?
Im using org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter in my WEB.xml
Also, im using Springs jdbcTemplate (org.springframework.jdbc.object.StoredProcedure) to make the update and HibernateTemplate for loading... Could this mess it up for me, ?
JSF BEAN
...
public String actionSave(){
//update through jdbcTemplate
caseService.saveAndSendCaseNote(caseNote);
reload list through hibernateTemplate
loadCaseNotes();
//return to same page
return null;
}
...
Service Class
...
@Transactional
public CaseNote saveAndSendCaseNote(CaseNote caseNote){
//save
caseDaoJdbc.saveCaseNote(caseNote);
//do sendmail
return caseNote;
}
...
spring config datasouce and jdbcTemplate and hibernateTemplate and transactionManager setup
...
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<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>
<!-- SessionFactory used by HibernateTemplate. Set hibernate mapping objects. -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFac toryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>portal/business/CaseNote.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTempla te">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransa ctionManager">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
...
Im using JSF1.1, Spring 2.0.8 and Hibernate 3.2.6.ga.
Example flow of a list and update page (Both on the same page).
1. User clicks save from a JSF page,
2. JSF Bean then execute a Service method. (This method is marked as @Transactional)
3. Service updates through DAO layer the hibernate object from the update page.
4. Service method return back to JSF BEAN (Is the transaction finish now, should there be a commit now?)
5. JSF Bean re-load the list of Hibernate objects to be presented on the page. (The newly updated Hibernate object should exist here, right?)
6. Return to the same JSF page. Showing the list of objects with the newly updated object.
Problem here for me is that the List of objects (5) doesnt contain the newly updated object (Done in 3). Instead the old object is loaded into the list.
Home come? if i reload the page, then the list will exist with the newly updated object value.
Could it be that the transaction doens't end until JSF page is reach and until then i cant refresh my hibernate list with the new object values?
If so, can i commit my changes just before i end the Service method (3) instead?
Im using org.springframework.orm.hibernate3.support.OpenSes sionInViewFilter in my WEB.xml
Also, im using Springs jdbcTemplate (org.springframework.jdbc.object.StoredProcedure) to make the update and HibernateTemplate for loading... Could this mess it up for me, ?
JSF BEAN
...
public String actionSave(){
//update through jdbcTemplate
caseService.saveAndSendCaseNote(caseNote);
reload list through hibernateTemplate
loadCaseNotes();
//return to same page
return null;
}
...
Service Class
...
@Transactional
public CaseNote saveAndSendCaseNote(CaseNote caseNote){
//save
caseDaoJdbc.saveCaseNote(caseNote);
//do sendmail
return caseNote;
}
...
spring config datasouce and jdbcTemplate and hibernateTemplate and transactionManager setup
...
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<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>
<!-- SessionFactory used by HibernateTemplate. Set hibernate mapping objects. -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFac toryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>portal/business/CaseNote.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTempla te">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransa ctionManager">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
...