ORMLite Dao does not update my entity
I am using ORMLite as the orm framework in my spring web application.
I config the dao in the spring context xml:
<bean id="userDao" class="com.j256.ormlite.spring.DaoFactory"
factory-method="createDao">
<constructor-arg index="0" ref="ormliteSource"/>
<constructor-arg index="1" value="com.springapp.model.User"/>
</bean>
And my UserService:
<bean id="userService" class="com.springapp.service.UserService">
<property name="userDao" ref="userDao"/>
</bean>
Then I create my UserServiceTests:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations =
{"file:src/main/webapp/WEB-INF/spring/root-context.xml",
"file:src/main/webapp/WEB-INF/spring/servlet.xml"})
public class UserServiceTests {
@Autowired
private UserService us;
@Test
public void insert() throws SQLException {
User u = new User();
u.setName("hguser");
u.setLoginName("hguser_login");
u.setLocked(true);
us.addEntity(u);
long id = u.getId();
User uu = us.queryById(id);
Assert.assertNotNull(u);
Assert.assertEquals("hguser", uu.getName());
uu.setLoginName("hguser_login2");
us.updateEntity(uu);
User uuu=us.queryById(id);
Assert.assertEquals("hguser_login2", uuu.getLoginName());
//us.deleteEntity(uuu);
}
}
Then I run maven clean compile test.
However the test result is not expected, it may success or fail.
And this is the success log and the fail log.
I am not sure if I miss anything which cause the strange result.
I hope someone can help me.
No comments:
Post a Comment