我有以下Spring / Hibernate配置:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="jndiDataSource" />
<property name="annotatedClasses">
<list>
...
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
我在我的代码库中广泛使用spring transaction annotations来控制事务传播方法。这一切都很有效。
我需要执行一次更新会影响很多行,并且我希望将其与其余的事务逻辑混合在一起。我想要做的最后一件事就是在一家瓷器店里公牛并将所有物品装入记忆中并循环通过它们一次改变它们。
我正在尝试类似的事情:
@Autowired
private SessionFactory sessionFactory;
...
String hql = "UPDATE TABLE_NAME SET COLUMN_LIST WHERE ID IN :list";
// I see the transaction and get an error when I try to start a new one.
Transaction trans = sessionFactory.getCurrentSession().getTransaction();
Query query = sessionFactory.getCurrentSession().createSQLQuery(hql);
query.setParameterList("list", listOfIds);
success = (query.executeUpdate() == listOfIds.size());
我已经尝试将其放入具有自己的事务指令的方法中,但是没有看到任何证据表明它正在执行(除了缺少错误)。
将自定义Hibernate SQL包含在Spring托管事务中的推荐方法是什么?
非常感谢。