Youhou, I just found the solution !
I'm not really sure what happened, but here are the steps I followed :
First of all, I changed the snipet like this (I don't know if it
counts, but you never know) :
final Query<AddressCity> query = ds.find(AddressCity.class);
query.filter("department", new
Key<AddressDepartment>(AddressDepartment.class, new
ObjectId("4ef315c46f46c52f3373c904")));
query.order("name");
query.asList();
This didn't seem to work.
But, after that I made some tests and I had the same problem with
other classes in my project.
The thing is that I use spring mvc, and when the application is
started and I invoke the DAOs (@Repository) everything works fine !
But when I run from a separate class (Test.java), instanciating
mongodb and morphia manually, the code of the DAO's didn't seem to
work (I copy-past from the DAO's to Test.java) !
So I searched all my objects to see what's wrong.
I eventually found that I forgot to put a @Reference annotation to the
"Address" encapsulating class :
Address :
private AddressCity city;
@Reference private AddressDepartment department;
@Reference private AddressCountry country;
so I just added a @Reference annotation :
@Reference private AddressCity city;
And after that I retested Test.java and it worked !
Now, there are some things I don't get :
- The class Address.java wasn't involved during my tests...
theorically, it shouldn't be a problem
- I removed the @Reference annotation and it still works O_o
So I don't know what to think right now. The problem seems solved but
I'm not sure why.
Last thing :
I also have a custom DataStore implementation, that spring calls when
my app starts.
"public class DataStoreCustomImpl extends DatastoreImpl implements
Datastore..."
I always call this implementation in order to retrieve a DataStore.
In order to avoid a warning in the logs, inside this implementation I
overrided the "find(final Class<T> clazz)" method like this :
/*
* (non-Javadoc)
*
* @see com.google.code.morphia.DatastoreImpl#find(java.lang.Class)
*/
@Override
public <T> Query<T> find(final Class<T> clazz) {
// Returns the Query object with disabled validation in order to
avoir
// some warnings.
// See
http://code.google.com/p/morphia/issues/detail?id=296
return super.find(clazz).disableValidation();
}
Maybe it also has something to do ? I sincerely don't know.
I overrided the method some time after I changed the snipet (see the
beggining of this post) in order to avoid the warnings.
Anyway, I put here all the steps I followed, maybe this will help
other people.
That's all folks, thanks and bb :)