Recently I began using Play framework 2.3.8.
However update of model is I am in trouble without work well.
By the way, save method works.
Update does not work with code like the following. (It will not be persisted to the database.)
User user = User.findByEmail(email);
user.remoteAddress = remoteAddress;
user.userAgent = userAgent;
user.latitude = latitude;
user.longitude = longitude;
user.lastLoginAt = new Date();
user.update();
However the following code will work as intended.
User newUser = new User();
newUser.id = user.id;
newUser.remoteAddress = remoteAddress;
newUser.userAgent = userAgent;
newUser.latitude = latitude;
newUser.longitude = longitude;
newUser.lastLoginAt = new Date();
newUser.update();
Why can not I update the original instance?
User class is as follows.
package models.entities;
import java.util.*;
import javax.persistence.*;
import com.avaje.ebean.annotation.*;
import play.db.ebean.*;
import play.db.ebean.Model.Finder;
import play.data.validation.Constraints.*;
import play.Logger;
import models.services.*;
/**
* @author satouf
*/
@Entity
@Table(name="user")
public class User extends Model {
@Id
public Long id;
@Column(nullable = false, columnDefinition = "varchar(32)")
public String userIdentifier;
@Column(nullable = false, columnDefinition = "varchar(255)")
public String loginId;
@Column(columnDefinition = "text")
public String loginPassword;
@Column(columnDefinition = "varchar(64)")
public String handleName;
@Email
@Column(nullable = false, columnDefinition = "varchar(255)")
public String email;
@Column(nullable = false, columnDefinition = "smallint default 0")
public short status;
@Column(columnDefinition = "varchar(64)")
public String lastRemoteAddress;
public String lastUserAgent;
public Date lastLoginAt;
public double latitude;
public double longitude;
@UpdatedTimestamp
public Date updatedAt;
@CreatedTimestamp
public Date createdAt;
public static Finder<Long, User> finder = new Finder<Long, User>(Long.class, User.class);
@Override
public String toString(){
return ("[id: " + id + ", userIdentifier: " + userIdentifier + ", loginId: " + loginId + ", handleName: "
+ handleName + ", latitude: " + latitude + ", longitude: " + longitude + "]");
}
}
user
a reserved word in it ? try to use@Table(name="users")
instead – Decideduser.update()
function? Or is it simply just not persisted to the database? – Drysalter