transactional

Spring multiple @Transactional datasources

。_饼干妹妹 提交于 2019-11-28 07:42:09
<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="transactionManager2"); to identify which transaction manager I use if I have multiple transaction managers?

Problem in Handling Unit of work using Hibernate JPA

此生再无相见时 提交于 2019-11-28 01:46:38
I use Spring + Hibernate + JPA I need to handle the list of customers by inserting their orders. Here is the Unit of work : for(Customer customer: CustomerList) { List<Order> orderList = customer.getOrders(); for(Order order: OrderList) { //1. Insert order into ORDER table //If insert fails due to Duplicate key then no rollback and I follow steps 2 & 3. //If insert fails due to any reason except duplicate key then rollback all the previous transactions //2. select the order record (If any issue during selection then rollbackall the previous transactions) //3. Update the order If status of the

Hibernate SQLQuery bypasses hibernate session cache

会有一股神秘感。 提交于 2019-11-28 01:36:06
问题 I'm "transactionalizing" some extensive database manipulation and I came across this issue where if I run sql queries through hibernate but not using the MQL approach, the view of the database doesn't appear correct. Specifically the code uses the hibernate in the more appropriate manner in most cases but there are places where someone decided to just execute sql. I don't like that they did this but at this point "it is what it is". I found an explanation that seems to explain it but all the

For web MVC Spring app should @Transactional go on controller or service?

会有一股神秘感。 提交于 2019-11-27 19:08:26
For WebApplicationContext, should I put @Transactional annotations in the controller or in services? The Spring docs have me a bit confused. Here is my web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Alpha v0.02</display-name> <servlet> <servlet-name>spring</servlet-name> <servlet

Spring @Transaction not starting transactions

余生颓废 提交于 2019-11-27 16:00:32
问题 I am using Spring 3 with Hibernate 3. I am trying to configure Spring declarative transaction, but no matter what I try, Spring transaction is not getting started. Here is my configuration File: applicationContext-hibernate.xml <tx:annotation-driven transaction-manager="txManager" /> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="mdbDataSource" class="org.apache.commons.dbcp

Entities Not Persisting - Spring + Hibernate + JPA

好久不见. 提交于 2019-11-27 14:08:48
问题 I'm using Spring + Hibernate + JPA and I have a situation where I can't get my entities to persist to the database. I've set up a service class that is annotated with @Transactional. It uses a DAO that contains an injected EntityManager. When I call the function on the service object I see a bunch of selects for the reads the DAO is doing, but no updates/deletes as a result of merges and removes issued by my DAO. Surely there's something wrong with my setup, but I can't see it. persistence

Why use @Transactional with @Service instead of with @Controller

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 11:42:50
问题 I have seen many comments in stack-overflow articles I found certain things about either @Transactional use with @Service or with @Controller "Usually, one should put a transaction at the service layer." "The normal case would be to annotate on a service layer level" "Think transactions belong on the Service layer. It's the one that knows about units of work and use cases. It's the right answer if you have several DAOs injected into a Service that need to work together in a single transaction

Showing a Spring transaction in log

江枫思渺然 提交于 2019-11-27 10:49:53
I configured spring with transactional support. Is there any way to log transactions just to ensure I set up everything correctly? Showing in the log is a good way to see what is happening. in your log4j.properties (for alternative loggers, or log4j's xml format, check the docs) Depending on your transaction manager, you can set the logging level of the spring framework so that it gives you more info about transactions. For example, in case of using JpaTransactionManager , you set log4j.logger.org.springframework.orm.jpa=INFO (this is the package of the your transaction manager), and also

@Transactional method calling another method without @Transactional anotation?

三世轮回 提交于 2019-11-27 10:27:25
I've seen a method in a Service class that was marked as @Transactional , but it was also calling some other methods in that same class which were not marked as @Transactional . Does it mean that the call to separate methods are causing the application to open separate connections to DB or suspend the parent transaction, etc? What's the default behavior for a method without any annotations which is called by another method with @Transactional annotation? Arun P Johny When you call a method without @Transactional within a transaction block, the parent transaction will continue to the new method

Declarative transactions (@Transactional) doesn't work with @Repository in Spring

只谈情不闲聊 提交于 2019-11-27 06:12:54
问题 I'm trying to make simple application using Spring, JPA and embedded H2 database. Recently I've come across this strange issue with declarative transactions. They just doesn't commit if I autowire my DAO with @Repository annotation. More specifically I get exception on flush: javax.persistence.TransactionRequiredException: Exception Description: No transaction is currently active Here is my setup: persistence.xml <persistence-unit name="schedulePU" transaction-type="RESOURCE_LOCAL"> <provider