相关疑难解决方法(0)

"在注释ConcurrentHashMap时,在hibernate中非法尝试将非集合映射为@OneToMany,@ ManyToMany或@CollectionOfElements"

我试过注释一个属性访问器,其返回值是一个映射,如下所示:

@MapKeyColumn(name="parameter_name")
@ElementCollection
public ConcurrentHashMap<String, Serializable> getParameterValues()
Run Code Online (Sandbox Code Playgroud)

这符合hibernate用户指南(第2.2.5.3.4节).但是,我得到:

org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: ConfigurationParameterBag.parameterValues
at org.hibernate.cfg.annotations.CollectionBinder.getCollectionBinder(CollectionBinder.java:324)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1723)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:1002)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:130)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:92)
Run Code Online (Sandbox Code Playgroud)

java hibernate

16
推荐指数
1
解决办法
4万
查看次数

如何使用hibernate JPA注释映射嵌套集合Map <Key,List <Values >>?

我有一节课,我不确定如何正确注释.

我对Holder :: data的目标:

  • 列表应该不是通过比较器而是通过数组中元素的自然顺序来维护顺序.(如果有帮助,可以是ndx列.)
  • 持有人将拥有唯一的数据参考,因此Cascade all也可能适用.

我也愿意采用不同的设计来移除地图,如果这样可以实现更清洁的设计.

@Entity
public class Holder extends DomainObject {
  private Map<Enum,List<Element>> data;
}

@Entity
public class Element extends DomainObject {
  private long valueId;
  private int otherData;
}

@Mappedsuperclass
public class DomainObject {
 // provides id
 // optimistic locking
 // create and update date
}
Run Code Online (Sandbox Code Playgroud)

java collections annotations hibernate jpa

15
推荐指数
1
解决办法
1万
查看次数

标签 统计

hibernate ×2

java ×2

annotations ×1

collections ×1

jpa ×1