我试图让MongoDB上的EclipseLink(2.4.1)在拥有关系时按预期工作。但是......
我必须要实体:
@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,......)但是我总是遇到这个例外。
任何帮助都会受到极大的关注。
答案 0 :(得分: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
最诚挚的问候, 克里斯