Hibernate OGM:如何存储列表<Double>?

Hibernate OGM: How to store a List<Double>?

是否可以使用 Hibernate OGM 和 mongodb 存储 List 而无需为 Double 类型创建实体。

示例:

@Entity
public class Series extends Default {
    private List<Double> results;

给出以下异常:

Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: Series, for columns: [org.hibernate.mapping.Column(results)]

如果我向列表添加一个@OneToMany 关系,我必须为 Double 创建一个实体,否则它会抛出:

Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class

您可以使用 UserTypeList<Double> 转换为 String,但您将无法在此字段上使用聚合函数。

您需要使用注解@ElementCollection

像这样:

@ElementCollection
private List<Double> results;