Reputation: 2996
I trying to make EclipseLink (2.4.1) over MongoDB works as expected when having relations. But ...
I've got to Entity:
@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;
...
and :
@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;
I try to get all Invoice having account.id = a parameter. I do this request :
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();
And the result is always the same :
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")
I've tried many thing (@JoinField, @OneToOne, ...) but I always run into that exception.
Any help would be greatly apprieciated.
Upvotes: 2
Views: 1035
Reputation: 21145
According to http://wiki.eclipse.org/EclipseLink/Examples/JPA/NoSQL#Step_6_:_Querying joins are not supported.
You might try mapping the foreign key with a read-only basic mapping and accessing it in the query directly. Or adding a query key for the fk field as described here http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Query_Keys
Best Regards, Chris
Upvotes: 2