KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am getting a ERROR: duplicate key value violates unique constraint "users_pkey" Detail: Key (userid)=(2701) already exists. whenever i use the persist model to update my user entity. In the code sample below: SetLoginAttempts takes in a user entity that has been queried and when i start the transaction i simply set one of the entity's fields and call persist(), then commit the transaction. /** * @param user * @param attemptNumber */ @Transactional public void setLoginAttempts(Users user, int attemptNumber){ user.setLoginAttempts(attemptNumber); System.out.println(user); } Here is how i reference and grab the entity manager: eFactory = Persistence.createEntityManagerFactory("persistenceUnit"); eManager = eFactory.createEntityManager(); When looking at the stack trace, i noticed that the commit actually injects an insert Call: INSERT INTO USERS (userID, EMAIL, ISLOCKED, LOGINATTEMPTS, passwordHash, passwordSalt, USERNAME, version) VALUES (?, ?, ?, ?, ?, ?, ?, ?) bind => [2701, admin@d.com, false, 1, $shiro1$SHA-256$500000$6mqzZ/d/3BLQuJqLh1dDhQ==$NKW7Z++o/JTvf884aDWhP3Uhpyb5fTPMrm4joWnw7nI=, [B@1a8e3115, admin, 1] What is the proper way to reference an entity manager in Spring roo, update a field and commit the changes? Edit I added the @Transactional to the method and the stack trace shows that this is creating the entity manager instance: 2012-03-14 23:49:15,503 ["http-bio-8080"-exec-18] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Creating new transaction with name [org.bixin.dugsi.service.UserService.setLoginAttempts]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; '' 2012-03-14 23:49:15,503 ["http-bio-8080"-exec-18] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Opened new EntityManager [org.eclipse.persistence.internal.jpa.EntityManagerImpl@46b9979b
Tags (comma-separated)
Save Edits
Cancel