Hey,
I'm having a little trouble getting the expected result out of a simple many to many mapping.
First things first - dependencies:
org.hibernate.ogm:hibernate-ogm-mongodb:4.0.0.Beta1
org.mongodb:mongo-java-driver:2.11.2
org.springframework.data:spring-data-mongodb:1.2.3.RELEASE
Code:
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import org.springframework.data.annotation.Id;
@Entity
public class A {
@Id
public String id;
@ManyToMany
public Set<B> bs;
}
Code:
import javax.persistence.Entity;
import org.springframework.data.annotation.Id;
@Entity
public class B {
@Id
public String id;
public String ts = "ssklskl";
public String shss = "hssla";
}
Code:
A a = new A();
template.save(a);
B b = new B();
template.save(b);
a = template.findById(a.id, A.class);
b = template.findById(b.id, B.class);
Set<B> bs = new HashSet<B>();
bs.add(b);
a.bs = bs;
template.save(a);
The Result when using the command line:
Code:
{ "_id" : ObjectId("523264e291fddeedcb688d2f"), "_class" : "com.beelite.beans.A", "bs" : [ { "_id" : ObjectId("523264e291fddeedcb688d30"), "ts" : "ssklskl", "shss" : "hssla" } ] }
I haven't changed any of the defaults. I was expecting just the IDs to be embedded and not the whole object. Am I missing something in my mapping?
Thanks in advance,
Brian