spring-transactions

hibernate session.flush with spring @transactional

北战南征 提交于 2020-01-12 14:04:36
问题 I am using Spring and Hibernate in my application and using Spring Transaction. So I have a service layer with annotation @Transaction on methods and DAO layer having methods for database query. @Transactional(readOnly = false) public void get(){ } The issue is when I want to save an object in the database,then I have to use session.flush() at the end of DAO layer method. Why? I think if I have annotated @Transaction , then Spring should automatically commit the transaction on completion of

Testing @TransactionalEvents and @Rollback

孤街醉人 提交于 2020-01-11 06:34:08
问题 I've been trying to test out @TransactionalEvents (a feature of Spring 4.2 https://spring.io/blog/2015/02/11/better-application-events-in-spring-framework-4-2) with our existing Spring JUnit Tests (run via either @TransactionalTestExecutionListener or subclassing AbstractTransactionalUnit4SpringContextTests but, it seems like there's a forced choice -- either run the test without a @Rollback annotation, or the events don't fire. Has anyone come across a good way to test @TransactionalEvents

Spring Data Neo4j- using transactions causes infinite loop

时光怂恿深爱的人放手 提交于 2020-01-06 15:57:07
问题 I am trying to integrate SDN with my spring-hibernate app. With minimal <neo4j:config> and <neo4j:repositories> configuration, it works fine. But when i include either @Neo4jTransactional or write a custom transactionManager i get an infinite loop in creating nodeEntityStateFactory bean in the intercept method in ConfigurationClassEnhancer class. Here is the exception i get. java.lang.IllegalStateException: Singleton 'nodeEntityStateFactory' isn't currently in creation Here is the intercept

Spring data @transactional not rolling back with SQL Server and after runtimeexception

老子叫甜甜 提交于 2020-01-06 03:41:04
问题 I've enabled my spring application to use transactions and annotated my service method accordingly but the changes to my DB persist when a RuntimeException is thrown. My Spring configuration looks like this: <!-- Data Source. --> <jee:jndi-lookup id="dataSource" jndi-name="java:/jdbc/BeheermoduleDS"/> <!-- JPA Entity Manager. --> <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:/jpa/BeheermoduleDS"/> <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">

Injection of autowired dependencies failed

回眸只為那壹抹淺笑 提交于 2020-01-06 03:33:12
问题 I'm trying to realize the same as in Spring error when trying to manage several classes that share a common base class? But I'm still getting this Exception: Error creating bean with name 'com.example.model.CategoryTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.example.model.CategoryService com.example.model.CategoryTest.service; nested exception is org.springframework.beans

spring transactions in a spawned off thread

*爱你&永不变心* 提交于 2020-01-05 07:33:29
问题 im working on an existing system and need to have my spring transaction manager attach to a thread thats being spawned off of a master job thread. i keep getting this exception org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession

How does HibernateTemplate and Spring @Transactional work together?

强颜欢笑 提交于 2020-01-05 04:58:10
问题 We use HibernateTemplate in our DAOs for all the CRUD operations. My question is, we use spring @Transactional on the services, Because the spring is managing the transactions, how does the HibernateTemplate behave in the senario where I update multiple DAOs. Meaning does HibernateTemplate use same session across different DAOs when Spring @Transactional is used? @Transactional public boolean testService(SObject test)[ dao1.save(test.getOne()); dao2.save(test.gettwo()); } This is how the DAO

Spring @Transactional annotation is not working

风流意气都作罢 提交于 2020-01-05 03:08:06
问题 I'm trying to run entityManager.merge(myEntity) within the following method but it seems that the @Transactional annotation is ignored. The Hibernate configuration seems to be fine because I can successfully fetch data from the db but it's not possible to write to the db. I'm using Spring version 3.2.3. Why are the writing db operations not working? my method that does not work package com.reflections.importer.bls; ... @Service class BlsGovImporter { ... @Transactional private void

Manage transactions with multiple datasource, entity managers for same application code

柔情痞子 提交于 2020-01-03 03:14:08
问题 I'm building a spring boot application that has multiple datasources, entity managers, transaction managers and databases. Each one is for a customer and share same DAOs, Services. The swicth betweeen datasource work perfectly. But I have problem with transaction Here my configuration: package org.foo.config; @Configuration @EnableJpaRepositories(basePackages = "org.foo") @EnableTransactionManagement public class DataSourceConfiguration { @Value("#{'${load.datasources}'.split(',')}") private

CreateQuery is not valid without active transaction

空扰寡人 提交于 2019-12-30 09:41:02
问题 I'm trying to use the Spring @Transactional annotation, but i have problems when the method findAll is called and i have this error: org.hibernate.HibernateException: createQuery is not valid without active transaction at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:352) at com.sun.proxy.$Proxy57.createQuery(Unknown Source) at org.munaycoop.taskmanager.daos.PersonDataAccesObject.findAll(PersonDataAccesObject.java