Search code examples
javamongodbhibernatehibernate-ogm

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


Is it possible to store List with Hibernate OGM and mongodb without creating a Entity for type Double.

Example:

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

Gives the following exception:

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

If I add a @OneToMany relation to the List I have to create a Entity for Double otherwise it will throw:

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

Solution

  • You need to use the annotation @ElementCollection.

    Like this:

    @ElementCollection
    private List<Double> results;