I’m using play framework version 1.2.5 and I would like to retrieve all the connected users that didn’t update their session for 5 minutes, and then I would like to set their connection status to “disconnected”.
Here is my model :
@Entity
public class User extends Model {
@Required
public String name;
public boolean isConnected;
public Date lastConnectionDate;
}
And here is the Job that update the users :
Date fiveMinsAgo = new Date(new Date().getTime() - 5 * 60);
List<User> list = User.find("select u from User u where u.isConnected = true and u.lastConnectionDate < ?", fiveMinsAgo).fetch();
for (User user : list) {
// We set these accounts as disconnected
user.isConnected = false;
user.save();
}
This code does not seem to work. User are set to “disconnected” even if their lastConnectionDate is not older than 5 minutes ago.
Did I do something wrong ?
Is there a better way/code to do what I would like to do ? (like an UPDATE command)
Thank you for your help
Date.getTime() returns milliseconds.
Try this: