MARM MARM - 1 year ago 132
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();, "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:, "aaa");

How can I solve my problem? Thanks.

Answer Source

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:, "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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download