google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

"Cannot cast object" error when using Find #424

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What version are you using? (Morphia/Driver/MongoDB)
When I try this groovy source:

def Release release = datastore.find(Release.class, "releaseName =", 
"GIDRelease")

I get this exception:

| Error 2012-08-06 20:13:32,113 ["http-bio-8090"-exec-1] ERROR 
errors.GrailsExceptionResolver  - GroovyCastException occurred when processing 
request: [GET] /RelCal/release/calendar/GIDRelease
Cannot cast object '{ "releaseName" : "GIDRelease"}' with class 
'com.google.code.morphia.query.QueryImpl' to class 
'com.gap.release.calendar.Release'. Stacktrace follows:
Message: Cannot cast object '{ "releaseName" : "GIDRelease"}' with class 
'com.google.code.morphia.query.QueryImpl' to class 
'com.gap.release.calendar.Release'
   Line | Method
->>  28 | doCall  in com.gap.release.calendar.RelCalRestController$_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run . . in     ''
^   680 | run     in java.lang.Thread

Any clues?  I am using the find syntax as described here:

http://code.google.com/p/morphia/wiki/Datastore#Find_Methods

Original issue reported on code.google.com by barry.al...@gmail.com on 7 Aug 2012 at 3:35

GoogleCodeExporter commented 9 years ago
mongodb-morphia 0.7.8

Original comment by barry.al...@gmail.com on 7 Aug 2012 at 3:39

GoogleCodeExporter commented 9 years ago
You need to add .get() at the end to return the first one. See the fourth 
example in the docs : 
http://code.google.com/p/morphia/wiki/Datastore#Find_Methods

Original comment by scotthernandez on 7 Aug 2012 at 3:50

GoogleCodeExporter commented 9 years ago
Yep. adding .get() worked.  Thanks.

Original comment by barry.al...@gmail.com on 7 Aug 2012 at 4:05