Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » eclipselink 2.4 mongodb with criteria api(Is this a bug in FromImpl or something I'm doing wrong in my code)
eclipselink 2.4 mongodb with criteria api [message #876616] Fri, 25 May 2012 00:34 Go to next message
Bob Treacy is currently offline Bob TreacyFriend
Messages: 1
Registered: May 2012
Junior Member
I am using a nightly build (5-24-2012) of eclipselink-plugins-2 and eclipselink-plugins-nosql-2 to connect to mongodb using JPA Criteria API
I'm getting a ClassCastException when I try to query membership in an element collection

org.eclipse.persistence.internal.jpa.metamodel.SingularAttributeImpl cannot be cast to javax.persistence.metamodel.PluralAttribute
java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.metamodel.SingularAttributeImpl cannot be cast to javax.persistence.metamodel.PluralAttribute
at org.eclipse.persistence.internal.jpa.querydef.FromImpl.get(FromImpl.java:315)
at edu.harvard.iq.text.preprocess.MongoPairwiseAgreement.get(MongoPairwiseAgreement.java:42)
at edu.harvard.iq.text.preprocess.MongoPairwiseAgreementTest.testGet(MongoPairwiseAgreementTest.java:57)

@Override
public Boolean get(String setId,DocPair docPair, Integer methodId) {
...
CriteriaBuilder qb = em.getCriteriaBuilder();
CriteriaQuery<PairwiseMethods> c = qb.createQuery(PairwiseMethods.class);
Root<PairwiseMethods> p = c.from(PairwiseMethods.class);
// the following line is line 42 of MongoPairWiseAgreement that creates the issue:
c.select(p).where(qb.isMember(methodId, p.<List<Integer>>get("methodIds")));
TypedQuery<PairwiseMethods> query = em.createQuery(c);
...

this is line 315 of org.eclipse.persistence.internal.jpa.querydef.FromImpl.java:
if (!((PluralAttribute) attribute).getElementType().getPersistenceType().equals(PersistenceType.BASIC)) {


// Here are the essentials of my PairwiseMethods class:
@Entity
@NoSql(dataFormat=DataFormatType.MAPPED)
public class PairwiseMethods implements Serializable {
@Id
@GeneratedValue
@Field(name = "_id")
protected String id;
protected String setId;
protected DocPair docPair;
@ElementCollection
protected List<Integer> methodIds;


This is what the data looks like in mongodb:
> db.PAIRWISEMETHODS.find()
{ "_id" : "4FBEA15C1A886598E77A44FE", "METHODIDS" : [ 1, 2 ], "SETID" : "testSet", "DOCPAIR" : [ { "DOC1ID" : "doc1", "DOC2ID" : "doc2" } ] }

[Updated on: Fri, 25 May 2012 12:52]

Report message to a moderator

Re: eclipselink 2.4 mongodb with criteria api [message #878519 is a reply to message #876616] Tue, 29 May 2012 13:26 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

In the JPA Criteria API (and JPQL) you need to use join() not get() to query across an ElementCollection mapping.

You should get a better error message though, so please log a bug for that.


James : Wiki : Book : Blog : Twitter
Previous Topic:Toplink to EclipseLink Migration
Next Topic:JPA Error when new entity is added without DropAndCreate
Goto Forum:
  


Current Time: Mon Dec 22 22:48:25 GMT 2014

Powered by FUDForum. Page generated in 0.06339 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software