对于Serializable id类型的数据的测试

今天编写了一个这样的例子,然后进行了Junit测试,但是发现类型总是不匹配,最后测出如下

public <T> void deleteEntry(Class<T> t, Serializable id) {
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
T tt = this.findById(t, id);
session.delete(tt);
transaction.commit();
session.close();
}

测试方法:

@Test
public void testdeleteUser() throws Exception {
EntityDao entityDao = EntityDaoFactory.getInstance(EntityDao.class);
User user = entityDao.findById(User.class, 1L);
entityDao.deleteEntry(user.getClass(), 1L);
}

同学说serilizable可以接收String 和Integer两种类型数据,所以就按照这个思维方式填写的

原文地址:https://www.cnblogs.com/liuyangfirst/p/6027523.html