Hibernate错误笔记

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.ecp.eipd.its.core.entity.TestCase#1]
 

在做Junit测试的时候测试update对象的方法,对同一个对象进行update

TestCaseDTO testCaseDTO = new TestCaseDTO();
		testCaseDTO = testCaseService.findUniqueById(1);

		TestCaseDTO testCaseDTO2 = new TestCaseDTO();
		testCaseDTO2 = testCaseService.findUniqueById(1);
		testCaseDTO2.setCaseName("Test 2st");

		testCaseService.update(testCaseDTO2); //出错

		Assert.assertNotEquals(testCaseDTO, testCaseDTO2);
 
解决办法:
serviceImpl:

// testCaseDAO.update(entity); 改成下面的merge

testCaseDAO.merge(entity);
 

你可能感兴趣的:(Hibernate)