2013-02-13 1 views
2

MongoDB를 통해 EclipseLink (2.4.1)를 만들려고 할 때 관계가있을 때 예상대로 작동합니다. 하지만 ...EclipseLink MongoDB @ManyToOne classCastException 매우 간단한 예제로

은 내가 엔티티에 도착했습니다

@Entity 
@NoSql(dataType="account", dataFormat=DataFormatType.MAPPED) // dataType -> collectionName, MAPPED -> because object are transformed into a MAP in MongoDB 
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "email")) 
public class Account extends JPAMongoBaseEntity { 
    @Id 
    @Field(name="_id") 
    @GeneratedValue 
    private String id; 

    @Override 
    public String getId() { return id;}; 
    public void setId(String id) { this.id = id;}; 

    // Must be unique (id fonc) 
    @NotNull 
    @Size(min = 1, max = 256) 
    @Email 
    private String email; 
... 

과 :

@Entity 
@NoSql(dataType="invoice", dataFormat=DataFormatType.MAPPED) // dataType -> collectionName, MAPPED -> because object are transformed into a MAP in MongoDB 
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "label")) 
public class Invoice extends JPAMongoBaseEntity { 
    @Id 
    @Field(name="_id") 
    @GeneratedValue 
    private String id; 

... // Relations 
    @ManyToOne 
    private Account account; 

내가 account.id = 매개 변수를 가진 모든 송장을 얻을하려고합니다. 나는이 요청을 수행

TypedQuery<Invoice> q = em.createQuery("Select i from Invoice i join i.account a where a.id=:accountId", Invoice.class); 
q.setParameter("accountId", accountId); 
List<Invoice> res = q.getResultList(); 

을 그리고 결과는 항상 동일합니다 : 나는 많은 일을 해봤

Internal Exception: java.lang.ClassCastException: org.eclipse.persistence.eis.mappings.EISOneToOneMapping cannot be cast to org.eclipse.persistence.mappings.OneToOneMapping 
Query: ReadAllQuery(referenceClass=Invoice jpql="Select i from Invoice i join i.account a where a.id=:accountId") 

(@JoinField, @OneToOne, ...)하지만 난 항상로 실행 그 예외.

도움이 될 것입니다.

답변

2

에 따르면 http://wiki.eclipse.org/EclipseLink/Examples/JPA/NoSQL#Step_6_:_Querying 조인은 지원되지 않습니다.

외부 키를 읽기 전용 기본 매핑으로 매핑하고 쿼리에서 직접 액세스 해보십시오. 답변 여기 http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Query_Keys

최고 감사합니다, 크리스

+0

감사의 설명 된대로 또는 FK 필드에 대한 쿼리 키를 추가. 나는 기사를 보았지만 6 단계에서 주어진 예제는 join의 예제를 보여준다. Query query = em.createQuery ("Order from o oorderline l where l.description = : desc"); query.setParameter ("desc", "shipping"); 리스트 orders = query.getResultList();'. 이 예제는 EclipseLink와 MongoDB에서는 작동하지 않습니다 (그러나 의사는 가능하다고 말합니다). 향후 버전에서 지원 될 예정인지 알고 계십니까? – jmcollin92

+0

조인은 MongoDB에서 지원하지 않으므로 불가능합니다. 포함 된 ElementCollection에 사용 된 조인 구문이 지원되지만 실제 조인은 지원되지 않습니다.이 예제에서는 orderLines가 포함되어 액세스 할 수 있습니다. (ManyToOne, OneToOne, OneToMany, ManyToMany에 대한 조인은 지원되지 않습니다. ElementCollection에 대한 조인은 괜찮습니다) – James