我有一个简单的JPA映射示例,包括一个映射。 TestEntity具有SubEntity-Objects和一些密钥的映射。我会预料到地图密钥会被存储。相反,它们是空的。下面是代码:JPA2.0映射密钥没有存储
@Entity
public class TestEntity {
@OneToMany
public Map<String, SubEntity> map = new HashMap<String, SubEntity>();
@Id
@GeneratedValue(strategy = AUTO)
protected long id;
public String name;
public TestEntity() {
}
public TestEntity(String name) {
this.name = name;
}
}
这是子实体:
@Entity
public class SubEntity {
@Id
@GeneratedValue(strategy = AUTO)
protected long id;
public SubEntity() {
}
String subEntityName;
public SubEntity(String name) {
this.subEntityName = name;
}
}
这里是测试代码:创建并存储
EntityManager em = EntityManagerService.getEntityManager();
em.getTransaction().begin();
for (int i = 0; i < 10; i++) {
TestEntity e = new TestEntity("MyNameIs" + i);
for (int j = 0; j < 8; j++) {
SubEntity se = new SubEntity("IamNo" + j + "." + i);
e.map.put("Key" + i * 100 + j, se);
em.persist(se);
}
em.persist(e);
}
em.getTransaction().commit();
的所有对象。只是映射表中的键值全部为空。我的错误在哪里?我正在使用eclipselink2.4.1和Derby 10的JPA2。
“相反,他们是。” - 什么? – contradictioned