transactional

Spring3 's @Transactional @Scheduled not committed to DB?

别来无恙 提交于 2019-12-18 16:31:11
问题 This is my 1st time trying Spring3's @Scheduled , but found I cannot commit to DB. This is my code : @Service public class ServiceImpl implements Service , Serializable { @Inject private Dao dao; @Override @Scheduled(cron="0 0 * * * ?") @Transactional(rollbackFor=Exception.class) public void hourly() { // get xxx from dao , modify it dao.update(xxx); } } I think it should work , I can see it starts-up hourly and load xxx from DB , but data is not committed to DB. There's been tx:annotation

org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode

痴心易碎 提交于 2019-12-18 09:10:16
问题 I am using Spring , JPA, Hibernate, Postgresql. I can upload/insert a file to the database. But I got the error when tried to access the file. EVERE: Servlet.service() for servlet default threw exception org.postgresql.util.PSQLException: Large Objects may not be used in auto-commit mode. at org.postgresql.largeobject.LargeObjectManager.open(LargeObjectManager.java:200) at org.postgresql.largeobject.LargeObjectManager.open(LargeObjectManager.java:172) at org.postgresql.jdbc2

LazyInitializationException Within a @Transactional Method

只愿长相守 提交于 2019-12-18 06:08:54
问题 I am running into the org.hibernate.LazyInitializationException error when I try to access a lazy loaded exception when excecuting the following: @Transactional public void displayAddresses() { Person person = getPersonByID(1234); List<Address> addresses = person.getAddresses(); // Exception Thrown Here for(Address address : addresses) System.out.println(address.getFullAddress()); } My entities look like this: @Entity @Table("PERSON_TBL") public class Person { ... @OneToMany(cascade

Spring multiple @Transactional datasources

早过忘川 提交于 2019-12-17 18:27:16
问题 <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="data.emf" /> </bean> <tx:annotation-driven transaction-manager="transactionManager" /> <bean id="transactionManager2" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="data.emf" /> </bean> <tx:annotation-driven transaction-manager="transactionManager2" /> In my service layer, can I use @Transactional(name=

How to use spring transaction in multithread

拜拜、爱过 提交于 2019-12-17 07:20:19
问题 I have a method as below: ClassA.java @Transactional public void methodA(){ ExecutorService executorService = Executors.newFixedThreadPool(4); executorService.execute(new Runnable() { public void run() { classB.methodB(); } }); } ClassB.java @Transactional public void methodB(){ updateDB(); } Can the methodB work well? Per my understanding, methodB will attach the transaction of methodA, what if methodA exits before methodB? I guess only methodA can be commited by the transaction. But methodB

Spring @Transactional - isolation, propagation

落花浮王杯 提交于 2019-12-17 01:20:27
问题 Can someone explain what isolation & propagation parameters are for in the @Transactional annotation via real-world example? Basically when and why I should choose to change their default values. 回答1: Good question, although not a trivial one to answer. Propagation Defines how transactions relate to each other. Common options: Required : Code will always run in a transaction. Creates a new transaction or reuses one if available. Requires_new : Code will always run in a new transaction.

How do I inject mocks into a Spring class marked as “@Transactional”?

自作多情 提交于 2019-12-14 02:23:48
问题 I'm using SPring 3.1.1.RELEASE and JUnit 4.8.1. In my test class, I want to mock a private field and discovered the beauty of "ReflectionTestUtils" ... @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:test-context.xml" }) public class OrderServiceTest extends AbstractTransactionalJUnit4SpringContextTests … @Autowired private OrderService m_orderSvc; @Test public void testGetPDOrders() throws QuickBaseException, Exception { … ReflectionTestUtils.setField(m_orderSvc,

Spring Transactional TimeOut

风流意气都作罢 提交于 2019-12-13 13:33:17
问题 I am trying to use spring @Transactional annotation and timeout parameter. I basically test the code with put some Thread.sleep() codes. Then i get timeout exception as i expected. Also i want to get timeout exception when database operations take longer than my timeout period. I lock a record in a table in my database with for update select statement. I try to update that record. But program wait and do nothing. Here my sample code. @Transactional(rollbackFor = Exception.class, timeout=5)

Spring transactional context doesn't persist data

醉酒当歌 提交于 2019-12-13 12:27:24
问题 I know that my problem is a common problem, but I've checked a lot of questions here, checked Spring documentation and I really don't know what I am doing wrong. My problem: I've got a Spring WebFlow project using JPA (implementation: OpenJPA + MySQL database). I use Spring ORM to inject EntityManager (by @PersistenceContext annotation) to my simple RegisterDAO. I have configured GlassFishs (which I am using) connection pools for using MySQL and everything works - I can work with my database,

What data is stored in transaction?

时光毁灭记忆、已成空白 提交于 2019-12-13 04:33:01
问题 Which data is stored in @Transactional services, especially in the transaction? If I have a controllers layout, services layout, daos and database - why I have to use my services with @Transactional annotation and what data is stored between these layouts? For example, I send some object data and I want it write to database. Well, in the transaction will be stored all this data? But what if I only update some data in database by giving and id of the object? Can you help me understand it? 回答1: