Hi, and thanks for the reply!
I put readOnly=true and now there is no update statement. Still I cannot get the data from the DB
This is my code:
Code:
public void save(User entity, UsersHelper usersHelper) {
String password = entity.getPassword();
if (StringUtils.hasText(password)) {
entity.setPassword(SecurityUtils.hashPassword(entity.getUsername(), password));
} else {
User old = findByIdNewTransaction(entity.getId());
String oldPassword = old.getPassword();
entity.setPassword(oldPassword);
}
If I remove the <persistence-context> tag I get the old password. If I have this tag, old.getPassword(); returns the new one.
Here is the log with <persistence-context>
13:48:58,593 DEBUG AnnotationTransactionAttributeSource:107 - Adding transactional method [findByIdNewTransaction] with attribute [PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnl y]
13:48:58,593 DEBUG JpaTransactionManager:285 - Found thread-bound EntityManager [org.hibernate.ejb.EntityManagerImpl@1f2a8f5] for JPA transaction
13:48:58,593 DEBUG JpaTransactionManager:371 - Creating new transaction with name [eu.dreamix.brokers.model.dao.BaseDao.findByIdNewTr ansaction]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnl y
13:48:58,593 DEBUG DriverManagerDataSource:163 - Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost/brokers?characterEncoding=UTF-8]
13:48:58,609 DEBUG JpaTransactionManager:348 - Exposing JPA transaction as JDBC transaction [SimpleConnectionHandle: com.mysql.jdbc.Connection@12036a1]
Hibernate: select user0_.id as id28_, user0_.active as active28_, user0_.date_created as date3_28_, user0_.date_modified as date4_28_, user0_.contract as contract28_, user0_.password as password28_, user0_.username as username28_ from users user0_ where user0_.id=? limit ?
13:48:59,593 DEBUG JpaTransactionManager:730 - Initiating transaction commit
13:48:59,593 DEBUG JpaTransactionManager:451 - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@1f2a8f5]
13:48:59,593 DEBUG JpaTransactionManager:539 - Not closing pre-bound JPA EntityManager after transaction
and without <persistence-context>
13:46:57,125 DEBUG AnnotationTransactionAttributeSource:107 - Adding transactional method [findByIdNewTransaction] with attribute [PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnl y]
13:46:57,140 DEBUG JpaTransactionManager:371 - Creating new transaction with name [eu.dreamix.brokers.model.dao.BaseDao.findByIdNewTr ansaction]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnl y
13:46:57,140 DEBUG JpaTransactionManager:322 - Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@2be20e] for JPA transaction
13:46:57,156 DEBUG DriverManagerDataSource:163 - Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost/brokers?characterEncoding=UTF-8]
13:46:57,203 DEBUG JpaTransactionManager:348 - Exposing JPA transaction as JDBC transaction [SimpleConnectionHandle: com.mysql.jdbc.Connection@cf9a33]
Hibernate: select user0_.id as id28_, user0_.active as active28_, user0_.date_created as date3_28_, user0_.date_modified as date4_28_, user0_.contract as contract28_, user0_.password as password28_, user0_.username as username28_ from users user0_ where user0_.id=? limit ?
13:46:58,578 DEBUG JpaTransactionManager:730 - Initiating transaction commit
13:46:58,578 DEBUG JpaTransactionManager:451 - Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@2be20e]
13:46:58,578 DEBUG JpaTransactionManager:534 - Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@2be20e] after transaction
13:46:58,578 DEBUG EntityManagerFactoryUtils:313 - Closing JPA EntityManager