MARM MARM - 2 months ago 20
Android Question

ORMLite where clausule in String Array

I use ormlite and I have a db with a field:

public static final String NAME = "name";
@DatabaseField (canBeNull = false, dataType = DataType.SERIALIZABLE, columnName = NAME)
private String[] name = new String[2];


And I would like to get all elements that name[0] and name[1] are "car". I try to add a where clausule like:

NAMEDB nameDB = null;
Dao<NAMEDB, Integer> daoName = this.getHelper().getDao(NAMEDB.class);
QueryBuilder<NAMEDB, Integer> queryName = daoName.queryBuilder();
Where<NAMEDB, Integer> where = queryName.where();
where.in(nameDb.NAME, "car");


But it doesn't work because it's an array string.

I have other fields:

public static final String MARK = "mark";

@DatabaseField (canBeNull = false, foreign = true, index = true, columnName = MARK)
private String mark = null;


And I can do this:

whereArticulo.in(nameDB.MARK, "aaa");


How can I solve my problem? Thanks.

Answer

Unfortunately ORMLite does not support querying fields that are the type SERIALIZABLE. It is storing the array as a serialized byte[] so you cannot query against the values with an IN query like:

where.in(nameDb.NAME, "car");

ORMLite does support foreign collections but you have to set it up yourself with another class holding the names. See the documentation with sample code:

http://ormlite.com/docs/foreign-collection