2013-08-19 3 views
1

Mongo 및 Play 2.1.3에서 Kundera를 사용하고 있습니다. 내 응용 프로그램에는 User 엔터티와 Document 엔터티가 있습니다. 사용자는 여러 개의 문서 (oneToMany)를 가지며 문서는 사용자에게 속합니다. 먼저 사용자를 만들고 유지하고 해당 사용자에게 문서를 추가 할 수 있습니다. 문서를 생성하고 유지할 때 사용자를 참조하는 userID가 User 엔터티의 userID와 다릅니다. 그리고 사용자 문서 ArrayList도 항상 null입니다.Kundera & MongoDB (Play 2.1.3에서) 양방향 관계가 DB에서 올바르게 참조되지 않습니다.

So here's relevant parts of my entities: 

@Entity(name="User") 
@Table(name="User", schema="[email protected]") 
public class User { 

    @GeneratedValue 
    @Id 
    @Column(name="_id") 
    private String userID; 

    @Required 
    @Column(name="name") 
    private String name; 
    (...) 

    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy="owner") 
    private List<Document> documents; 
    (...) 
} 


@Entity(name="Document") 
@Table(name="Document", schema="[email protected]") 
public class Document { 

    @GeneratedValue 
    @Id 
    @Column(name="_id") 
    private String documentID; 

    @Required 
    @Column(name="name") 
    private String name; 

    (...) 

    @ManyToOne(fetch = FetchType.LAZY) 
    @JoinColumn(name="userID") 
    private User owner; 
    (...) 
} 

-- 

The user is created and persisted. The documents are created afterwards with something like the following: 

public static void createDocument(String name, User user) { 
EntityManagerFactory emf = Application.getEmf(); 
    Document document = new Document(); 
    document.setName(name); 
    ... 
    EntityManager em = emf.createEntityManager(); 
    document.setOwner(user); 
    em.persist(document); 
    em.close(); 
} 

In the db: 
db.User.find() 
{ "_id" : "5211067576aae40da0595eb0", "name" : "Name of the user" (...) } 

db.Document.find() 
{ "_id" : "52113c1376aae337b4537028", "name": "name", "userID" : "52113c1376aae337b4537029" } 

I was expecting the userID in the document to be the same as the User _id. 
As I said when I try to access the user's documents ArrayList it's always null. 

What am I doing wrong here? :) 
Thanks in advance. 

답변

0

답변으로 kundera-discuss 그룹.