tak si aj sam odpoviem, snad to niekomu pomoze:
treba nastavit transakcny mechanizmus pomocou AOP nasledovne:
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="NEVER"/>
<tx:method name="find*" read-only="true" propagation="NEVER"/>
<tx:method name="save*" rollback-for="Exception"/>
<tx:method name="update*" rollback-for="Exception"/>
<tx:method name="delete*" rollback-for="Exception"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<tx:annotation-driven transaction-manager="txManager"/>
<aop:config>
<aop:pointcut id="serviceOperation" expression="execution(*
com.*.service.impl.*..*ManagerImpl.*(..))"/>
<aop:advisor advice-ref="txAdvice"
pointcut-ref="serviceOperation"/>
</aop:config>
<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
Ivan
Info wrote / napísal(a):
zdravim konferenciu,
pouzivam Hibernate a Spring. potrebujem vykonat jeden update nad DB mimo
klasickeho pristupu Hibernate pomocou prikazu createSQLQuery:
public void updateZdroj(final Long id) {
final HibernateCallback callback = new HibernateCallback() {
public Object doInHibernate(final Session session) throws
HibernateException {
session.beginTransaction();
int result = session.createSQLQuery("update zdroj set hodnota =
hodnota + 1 where id = " + id).executeUpdate();
session.getTransaction().commit();
return result;
}
};
getHibernateTemplate().execute(callback);
}
tento kod je v triede ZdrojDaoHibernate (implements ZrojDao).
skusal som aj dat
@Transactional (propagation=Propagation.REQUIRED)
public interface ZdrojDao extends GenericDao<Carrier, Long> {
aj konktrentne nad funkciu updateZdroj:
@Transactional (readOnly=false)
void updateZdroj(Long id);
a skusal som aj dat parameter Hibernate:
<prop key="hibernate.current_session_context_class">thread</prop>
bohuzial nic nepomohlo chyba je vzdy nasledovna:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and
configuration does not allow creation of non-transactional one here
org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574)
nepoznate niekto presny postup ako pouzivat createSQLQuery?
dakujem
Ivan
________________________________________________
Message sent using Webmail 2.7.9