2

我试图让 EclipseLink (2.4.1) over MongoDB 在有关系时按预期工作。但 ...

我必须实体:

@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 = 参数的 Invoice。我提出这个要求:

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、...),但我总是遇到那个异常。

任何帮助将不胜感激。

4

1 回答 1

2

根据 http://wiki.eclipse.org/EclipseLink/Examples/JPA/NoSQL#Step_6_:_Querying 连接不受支持。

您可以尝试使用只读基本映射映射外键并直接在查询中访问它。或为 fk 字段添加查询键,如此处所述 http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Query_Keys

最好的问候,克里斯

于 2013-02-15T15:33:09.903 回答