I have some problems while implementing filters in mongodb using morphia POJO mapper.
In my class (for example SampleClass
), when i try to access the fields of an @Entity
class (in our case it's Person
), I find the field access works fine, using dot notation for general fields like int, string, maps or direct embedded objects.
The issue is I could not understand how it works for the case of a "List of Objects" referenced in the Person
class. (Assume here, a person can have many addresses, so this Person
class has a field addresses
which holds a list of Address
objects)
@Entity
Class Person
{
String name;
int age;
String type;
private Map<String, String> personalInfo= new HashMap<String, String>();
@Reference
List<Address> addresses = new ArrayList<Address>;
}
@Entity
Class Address
{
String streetName;
int doorNo;
}
For example, I want to apply a filter on streetName
of the Address
object which is in the addresses
List
public class SampleClass
{
private Datastore ds;
Query<Node> query;
CriteriaContainer container;
// connections params etc....
public List<Person> sampleMethod()
{
query = ds.find( Person.class ).field( "type" ).equal( "GOOD");
container.add( query.criteria( "name" ).containsIgnoreCase("jo" ));
// general String field in the Person Class ---- OKAY, Work's Fine
container.add( query.criteria( "personalInfo.telephone" ).containsIgnoreCase( "458" ) );
// Map field in the Person Class, accessing telephone key value in the map --- OKAY, Work's Fine
container.add( query.criteria( "addresses.streetname").containsIgnoreCase( "mainstreet" ) );
// List of address object in the Person Class, name of the field is 'addresses'
// ----NOT OKAY ????????? -- Here is the problem it returns nothing, even though some value exists
return readTopography( query.asList() );
}
}
Am I doing something wrong while accessing the objects in a list?