queryBuilders selectColumns

8 views
Skip to first unread message

Arthur Grailard

unread,
Oct 9, 2019, 12:17:03 PM10/9/19
to ORMLite Developers
Hello,

Do someone have an answer to this subject please ?
https://sourceforge.net/p/ormlite/bugs/169/

My problem is:

I have an entity:
public class MyEntity {

@DatabaseField(columnName = "ID", generatedId = true)
private int id;

@DatabaseField(columnName = "PARENT", foreign = true)
private MyEntity parent;
}

And i want to make a query returning all MyEntity which are parent of another MyEntity.

So what I did:

public List<MyEntity> getAllParents() throws SQLException {
QueryBuilder<MyEntity, Integer> queryBuilderChilds = queryBuilder();
queryBuilderChilds.where().isNotNull("PARENT");
queryBuilderChilds.selectColumns("PARENT");

QueryBuilder<MyEntity, Integer> queryBuilderParent = queryBuilder();
queryBuilderParent.where().in("ID", queryBuilderChilds);

return queryBuilderParent.query();
}

But the doc say that when you use "selectColumns, the ID is automatically added. So i got a queryBuilder with 2 columns and my second where().in() throws :
java.sql.SQLException: There must be only 1 result column in sub-query but we found 2

Thanks for reading
Reply all
Reply to author
Forward
0 new messages