JPA2.0 map key is not stored
I have a simple JPA mapping example including a map. A TestEntity has a
map of SubEntity-Objects and some keys. I would have expected that the map
keys are stored. Instead they are . Here is the code:
@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;
}
}
This is the subentity:
@Entity
public class SubEntity {
@Id
@GeneratedValue(strategy = AUTO)
protected long id;
public SubEntity() {
}
String subEntityName;
public SubEntity(String name) {
this.subEntityName = name;
}
}
And here is the test code:
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();
All Objects are created and stored. Just the key values in the mapping
table are all null. Where is my mistake? I am using JPA2 with
eclipselink2.4.1 and Derby 10.
No comments:
Post a Comment