java - JPA 2 : How to use Map<String , Employee> 实体之间的 OneToMany 关系

标签 java hibernate exception jpa jpa-2.0

当我尝试在实体之间的 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/

相关文章:

java - 为什么可以改变java中抽象方法的返回类型?

java - Sencha 构建失败

java - 如何在java中动态读取对象属性?

mysql - Hibernate 生成不正确的 MySQL 脚本

c++ - 沙盒异常(外部库和 std::lib)

java - 设计 API 以获取用户的 xpath 输入

java - 查询语法异常 : Path expected for join

java - hibernate 空间 - 'Invalid endian flag value encountered' 异常

java - PBKDF2WithHmacSHA512 SecretKeyFactory 不可用

python - 获取完整的异常类型/消息和堆栈跟踪