transactional

Issue with @Transactional annotations in Spring JPA

只谈情不闲聊 提交于 2019-12-06 15:57:44
I have a doubt related to transactions within transactions. For background, I have a School entity object which has Set of Students entity object mapped to it. I am using Spring Data JPA which is taking care of all the crud operations. I have a SchoolManagementService class which has @Transactional(readonly=true) set at the class level and for all updating methods I am using @Transactional over them. In my SchoolManagementService class I have a method deleteStudents(List) which I have marked as @Transactional. In this method I am calling StudentsRepository.delete(studentId) again and again. I

which SessionFactory should be use for transactionManager?

守給你的承諾、 提交于 2019-12-06 15:41:07
<bean id="projectService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager" ref="transactionManager"/> <property name="target"> <bean class="com.company.project.company.services.ServiceImpl" init-method="init"> <property name="HRappsdao" ref="HRappsdao"/> <property name="projectdao" ref="projectdao"/> </bean> </property> <property name="transactionAttributes"> <props> <prop key="store*">PROPAGATION_REQUIRED</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="remove*">PROPAGATION_REQUIRED</prop> <prop key=

Hibernate ConstraintViolationException on SELECT query

非 Y 不嫁゛ 提交于 2019-12-06 11:01:19
I have a Persistent Class with multi-field unique constraint on it. But defined unique constraint is not sufficient for me because on one those field non-equal but similar values are unique too. I implement a checkUniqueConstraint method. In add and update methods of DAO class, I call checkUniqueConstraint before adding or updating persist object. checkUniqueConstraint method just run a SELECT query to find object similar to input and throw a check Exception where find some ones. public class PersistClassDao { public void checkUniqueConstraint(PersistClass persistObject) throws

How to use transaction-scoped persistence context for non-transactional reading query?

☆樱花仙子☆ 提交于 2019-12-06 08:17:06
问题 I read the Spring doc and it says: The @PersistenceContext annotation has an optional attribute type, which defaults to PersistenceContextType.TRANSACTION. This default is what you need to receive a shared EntityManager proxy. Does this mean I have to make EntityManager work in a transaction? How does it work for non-transactional method (reading query), such as the loadProductsByCategory in the below code? What does the "shared" mean? How can it use EntityManager sharing with others? Do I

Spring Hibernate - Could not obtain transaction-synchronized Session for current thread

巧了我就是萌 提交于 2019-12-05 20:00:05
Why am I posting this? After several hours of search / analysis / getting paranoid I would like to share my fault with you - I nailed down my cause of the problem. When did it happen? within the application server (in my case embedded tomcat) - tests had no problem on two specific @Services on which the methods got properly annotated with @Transactional What was not the problem? Missing @EnableTransactionManagement in the @Configuration Some weired AOP issue, eg having no default constructor in a Service not implementing an interface (AFAIK this problem does not exist anymore since Spring 4.0)

Commit during transaction in @Transactional

你说的曾经没有我的故事 提交于 2019-12-05 16:13:56
Is that possible to perform commit in the method that is marked as Spring's @Transactional ? @PersistenceContext private EntityManager em; @Transactional(propagation = Propagation.REQUIRED) public void saveMembersWithMultipleCommits(List<Member> members) throws HibernateException { Iterator<Member> it = members.iterator(); while (it.hasNext()) { while (it.hasNext()) { Member wsBean = it.next(); em.persist(wsBean); // overall commit will be made after method exit log.info("Webservices record " + wsBean + " saved. " + i++); } } } I would like to have commit to DB after say each 500 items. Is

Spring transactional context doesn't persist data

醉酒当歌 提交于 2019-12-05 11:27:45
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, but when I am persisting something - nothing happens (data are not persist to database). I know that

Transactionally writing files in Node.js

与世无争的帅哥 提交于 2019-12-05 03:44:16
I have a Node.js application that stores some configuration data in a file. If you change some settings, the configuration file is written to disk. At the moment, I am using a simple fs.writeFile . Now my question is: What happens when Node.js crashes while the file is being written? Is there the chance to have a corrupt file on disk? Or does Node.js guarantee that the file is written in an atomic way, so that either the old or the new version is valid? If not, how could I implement such a guarantee? Are there any modules for this? What happens when Node.js crashes while the file is being

Hibernate, Spring, @Transactional - surround with try/catch?

Deadly 提交于 2019-12-04 06:25:09
Im working on developing a webapplication with Spring 3 and Hibernate 3.6. Ive got some questions to the @Transactional Annotation and the structure of the code. -> When I use @Transactional (transaction management with Spring), do I have to surround the @Transactional -annotated methods with try/catch when calling them? For example, when I got a method which loads, changes and returns then an object and I call it from another class: do I have to surround the call with try/catch? maybe something goes wrong, no object is returned, database connection fails.. I dont know. until now, I thought

Spring @Transactional not creating required transaction

匆匆过客 提交于 2019-12-03 16:14:42
问题 Ok, so I've finally bowed to peer pressure and started using Spring in my web app :-)... So I'm trying to get the transaction handling stuff to work, and I just can't seem to get it. My Spring configuration looks like this: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=