0

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
gregor
  • 2,397
  • 2
  • 12
  • 18

2 Answers2

2

You need to use the annotation @ElementCollection.

Like this:

@ElementCollection
private List<Double> results;
Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30
-1

You can use UserType to convert your List<Double> to a String, but you will lose the availability to use aggregates functions over this field.

Sergio Lema
  • 1,491
  • 1
  • 14
  • 25
  • I don't think that's the issue, per docs https://docs.jboss.org/hibernate/stable/ogm/reference/en-US/html_single/?v=5.0 it seems that the collection should be initialized as mentioned by @Zircon – xiumeteo Feb 23 '17 at 17:00