我试图让 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、...),但我总是遇到那个异常。
任何帮助将不胜感激。