【问题标题】:org.hibernate.MappingException: Could not determine type for: java.util.List, at table: Schedule_assignedRoles, for columns: assignedRolesorg.hibernate.MappingException:无法确定类型:java.util.List,表:Schedule_assignedRoles,列:assignedRoles
【发布时间】:2016-05-19 12:28:49
【问题描述】:

我需要帮助,我正在尝试使用地图,但出现此错误:

原因:org.hibernate.MappingException:无法确定类型:java.util.List,表:Schedule_assignedRoles,列:[org.hibernate.mapping.Column(assignedRoles)] 在 org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:390) 在 org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:363) 在 org.hibernate.mapping.Collection.validate(Collection.java:310) 在 org.hibernate.mapping.IndexedCollection.validate(IndexedCollection.java:74) 在 org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:333) 在 org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443) 在 org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:802)

这是我的代码:

@Entity
public class Schedule extends PersistentObject implements Comparable<Schedule> {
   private String title;

   @ManyToOne
   private Agent target;

   @ElementCollection
   @MapKeyColumn(nullable = false)
   @Column(nullable = false)
   private Map<Long, List<Role>> assignedRoles = new HashMap<>();

   //gets e setters
}

谢谢! :D

【问题讨论】:

  • 谁告诉你可以使用 JPA 在 Map 中嵌入 List 类型的值?
  • 我不知道,我认为这是可能的。谢谢!

标签: java hibernate jpa mappingexception


【解决方案1】:

我认为使用@ManyToMany@OneToMany 足以完成您的任务

@Entity
public class Schedule extends PersistentObject implements Comparable<Schedule> {

   @Column
   private String title;

   @ManyToOne
   private Agent target;

   @OneToMany 
   private List<Unit> units = new List<>();

}

@Entity
public class Unit {

  @ManyToMany 
  private List<Role> assignedRoles = new List<>();

}

【讨论】:

  • 嘿,如果可能的话,我需要一张地图,因为日程安排必须保存一个带有角色列表的键(单位,其他对象)。无论如何,谢谢!
  • @renanlessa 无法使用地图。可能,您需要另一个实体。我更新了。
猜你喜欢
  • 2011-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-23
  • 1970-01-01
  • 2014-11-29
  • 1970-01-01
相关资源
最近更新 更多