当我尝试在实体之间的 OneToMany 关系中使用 Map 时,我遇到了问题。当我尝试在 map 中插入数据时,会抛出以下异常
Exception in thread "main" org.hibernate.HibernateException: null index column for collection
。
请解释这个异常并给我一个使用 Map<>
的小例子在关系中。
最佳答案
这里有一个很好的解释: http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Maps
对于 JPA2,我引用:
JPA 2.0 allows for a Map where the key is not part of the target object to be persisted. The Map key can be any of the following:
- A Basic value, stored in the target's table or join table.
- An Embedded object, stored in the target's table or join table.
- A foreign key to another Entity, stored in the target's table or join table.
关于java - JPA 2 : How to use Map<String , Employee> 实体之间的 OneToMany 关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14473798/