【发布时间】:2014-07-24 20:40:07
【问题描述】:
我创建了一个非常简单的 Spring Roo 1.2.5 项目,其中有一个实体类 MyEntity,它有几个字符串变量。
我加了一个
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
为MyEntity.java创建主键,并由Spring Roo生成
@Test
public void MyEntityIntegrationTest.testFindMyEntity() {
MyEntity obj = dod.getRandomMyEntity();
Assert.assertNotNull("Data on demand for 'MyEntity' failed to initialize correctly", obj);
Integer id = obj.getPrimaryKey();
Assert.assertNotNull("Data on demand for 'MyEntity' failed to provide an identifier", id);
obj = MyEntity.findMyEntity(id);
Assert.assertNotNull("Find method for 'MyEntity' illegally returned null for id '" + id + "'", obj);
Assert.assertEquals("Find method for 'MyEntity' returned the incorrect identifier", id, obj.getPrimaryKey());
}
在 MyEntityIntegrationTest_Roo_IntegrationTest.aj 文件中。但是有两个问题:
1) 类型是 int,那么为什么 Roo 将它分配给 Integer,然后测试是否为 null?如果类型为int,则结果不能为null
2) 由于 JDK 6 编译器无法解析 assertEquals(Integer, int) 的类型,最终断言无法编译:
The method assertEquals(String, Object, Object) is ambiguous for the type Assert MyEntityIntegrationTest_Roo_IntegrationTest.aj /mu/src/test/java/com/sas/mu line 47 Java Problem
我可以“修复”这个我将字段更改为 Integer 或 Long 但@Id 说原语 是允许的。
我怀疑这是 Roo 1.2.5 的错误吗?有解决办法吗?
【问题讨论】:
标签: spring-roo