I'm using mongodb to store json documents, and since I'm using Hibernate ORM for my relational models I've decided to use the OGM for the mongo ones.
Currently all of my OGM entities share the same parent class, it looks something like:
@Entity
public abstract class Document {
private static final Gson GSON = new Gson();
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Type(type = "objectid")
protected String id;
public String id() {
return this.id;
}
@Override
public String toString() {
return Document.GSON.toJson(this);
}
}
@Entity
public class Address extends Document {
private String city;
private String street;
private int house;
}
@Entity
public class Person extends Document {
private String name;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Set<Address> addresses;
}
(simplified of course)
What I expected that would happen when I persist a Person
instance is that two collections will be created in the db, one for Person
and the other for Address
, which I inferred:
The various inheritance strategies are not supported by Hibernate OGM, only the table per concrete class strategy is used
(Supported entity mapping - Hibernate OGM documentation)
But what happens in reality is that only one collection is created with the name Document
with two documents in it:
{
_id : id1,
DTYPE : Person,
name : name of person
}
{
_id : id2,
DTYPE : Address,
city : City of address,
street : Street of address
house : 3
}
What am I missing?
Thanks