Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Eclipselink mongoDB native query find() not working
Eclipselink mongoDB native query find() not working [message #923856] Wed, 26 September 2012 08:52 Go to next message
Bruno Aguiar is currently offline Bruno Aguiar
Messages: 1
Registered: September 2012
Junior Member
HI Everyone

I am recently working on a JAVA project with a mongoDB database. Being so i decided to use eclipselink 2.4. Regarding queries, it allows the usual "SQL like" queries but also (supposedly) allows native mongoDB queries. I followed this tutorial and put everything working. I am able to run a findOne() native mongoDB query (queryOne) but i am not able to run find() queries (queryAll does no work)...

Query queryOne = em.createNativeQuery("db.ORDER.findOne()", Order.class);

Query queryAll = em.createNativeQuery("db.ORDER.find()", Order.class);

I get this error when executing the query:

Exception in thread "main" Local Exception Stack: 
Exception [EclipseLink-6044] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.QueryException
Exception Description: The primary key read from the row [EISMappedRecord(
    value => DBQuery: myTest.ORDER -> undefined)] during the execution of the query was detected to be null.  Primary keys must not contain null.
Query: ReadAllQuery(referenceClass=Order )
    at org.eclipse.persistence.exceptions.QueryException.nullPrimaryKeyInBuildingObject(QueryException.java:912)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:586)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:562)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:776)
    at org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:781)
    at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:433)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1149)
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:852)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1108)
    at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:392)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1196)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2875)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1602)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1584)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1549)
    at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:231)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:411)
    at example.Test.testQuery(Test.java:171)
    at example.Test.main(Test.java:54)

The execution of the query resorting to the MongoDB shell:

{ "_id" : "5061DC17E4B0881F592675A5", "TOTALCOST" : 3187, "SHIPPINGADDRESS" : [     {   "POSTALCODE" : "L5J1H7",    "COUNTRY" : "Canada",   "PROVINCE" : "ON",  "CITY" : "Ottawa",  "STREET" : "17 Jane St." } ], "ORDERLINES" : [  {   "DESCRIPTION" : "machine",  "COST" : 2999,  "LINENUMBER" : 1 },     {   "DESCRIPTION" : "shipping",     "COST" : 129,   "LINENUMBER" : 2 },     {   "DESCRIPTION" : "installation",     "COST" : 59,    "LINENUMBER" : 3 } ], "VERSION" : NumberLong(1), "DESCRIPTION" : "Pinball machine", "CUSTOMER__id" : "5061DC17E4B0881F592675A4", "BILLINGADDRESS" : [   {   "POSTALCODE" : "L5J1H7",    "COUNTRY" : "Canada",   "PROVINCE" : "ON",  "CITY" : "Ottawa",  "STREET" : "17 Jane St." } ] }
{ "_id" : "5061DC17E4B0881F592675A6", "TOTALCOST" : 565, "SHIPPINGADDRESS" : [  {   "POSTALCODE" : "L5J1H7",    "COUNTRY" : "Canada",   "PROVINCE" : "ON",  "CITY" : "Ottawa",  "STREET" : "17 Jane St." } ], "ORDERLINES" : [  {   "DESCRIPTION" : "machine",  "COST" : 500,   "LINENUMBER" : 1 },     {   "DESCRIPTION" : "balls",    "COST" : 5,     "LINENUMBER" : 2 },     {   "DESCRIPTION" : "shipping",     "COST" : 60,    "LINENUMBER" : 3 } ], "VERSION" : NumberLong(1), "DESCRIPTION" : "Foosball", "CUSTOMER__id" : "5061DC17E4B0881F592675A4", "BILLINGADDRESS" : [  {   "POSTALCODE" : "L5J1H8",    "COUNTRY" : "Canada",   "PROVINCE" : "ON",  "CITY" : "Ottawa",  "STREET" : "7 Bank St." } ] }
{ "_id" : "5061DC17E4B0881F592675A8", "TOTALCOST" : 402, "SHIPPINGADDRESS" : [  {   "POSTALCODE" : "L5J1H7",    "COUNTRY" : "Canada",   "PROVINCE" : "ON",  "CITY" : "Ottawa",  "STREET" : "17 Jane St." } ], "ORDERLINES" : [  {   "DESCRIPTION" : "table",    "COST" : 300,   "LINENUMBER" : 1 },     {   "DESCRIPTION" : "balls",    "COST" : 5,     "LINENUMBER" : 2 },     {   "DESCRIPTION" : "rackets",  "COST" : 15,    "LINENUMBER" : 3 },     {   "DESCRIPTION" : "net",  "COST" : 2,     "LINENUMBER" : 4 },     {   "DESCRIPTION" : "shipping",     "COST" : 80,    "LINENUMBER" : 5 } ], "VERSION" : NumberLong(1), "DESCRIPTION" : "Pingpong table", "CUSTOMER__id" : "5061DC17E4B0881F592675A7", "BILLINGADDRESS" : [    {   "POSTALCODE" : "L5J1H8",    "COUNTRY" : "Canada", "PROVINCE" : "ON",    "CITY" : "Ottawa",  "STREET" : "7 Bank St." } ] }

If you could tell me how to fix this or a little workaround i would appreciate it.

Thanks
Re: Eclipselink mongoDB native query find() not working [message #930648 is a reply to message #923856] Tue, 02 October 2012 14:09 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please log a bug.

You should be able to use JPQL for the query.


James : Wiki : Book : Blog : Twitter
Previous Topic:Transform xml from one XSD version to another
Next Topic:select records where elementcollection contains one of parameter list
Goto Forum:
  


Current Time: Thu Oct 23 11:01:39 GMT 2014

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

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