I have 2 classes
List
@DatabaseTable(tableName = "loginsList")
public class LoginsList {
@DatabaseField(columnName = "loginListID", generatedId = true)
private int loginListID;
@DatabaseField(columnName = "listName")
private String listName;
@DatabaseField(columnName = "listDescription")
private String listDescription;
@DatabaseField(columnName = "current")
private boolean current;
@DatabaseField(columnName = "sent")
private boolean sent;
Login
@DatabaseTable(tableName = "login")
public class Login {
@DatabaseField(columnName = "loginID", generatedId = true)
private int loginID;
@DatabaseField(columnName = "user", foreign=true)
private User user;
@DatabaseField(columnName = "loggedIn")
private boolean loggedIn;
@DatabaseField(columnName = "loginTime")
private long loginTime;
@DatabaseField(columnName = "logoutTime")
private long logoutTime;
@DatabaseField(columnName = "loginsList", foreign = true)
private LoginsList loginsList;
I use ORMLite for the database. I want to know how can I get all logins for a list? I tried like this
tempLoginList = loginDao.queryForEq("loginsList", list);
where list is of type LoginsList and it is the list I want to get all the logins for, but it doesn’t work. How to do it with query builder?
That should work fine. Here’s a couple things to check for that may be getting in the way.
ORMLite stores an
intinLoginwhich is theloginListIDfield from theLoginsList. When you associate a list with aLogin, it must already have been created in the database so its id has already been generated.If you look at your query logs (turn on logging with something like the following log4j properties, you should see the associated query. You should be able to see the
loginid field being queried for. You need to make sure that it is correct.I have a lot of unit tests but not specifically around
dao.queryForEq(...)and foreign fields. I just added them to the code base and they work fine. Here’s my log output which might help: