I am quite new with Play Framework, and I am working on an existing project to solve some issues.
My problem is the following: when updating some values (the last edited User and last edited Date) in the database using the Ebean update() function I had a "OptomisticLockException". After trying several solutions I found on the internet, the one working was to use a raw sql query as explained here:
Update query instead of select + save
PlayFramework 2 + Ebean - raw Sql Update query - makes no effect on db
Using this, I have no problem with the Date, but when I want to update the User as well I get the following error: "[PersistenceException: No ScalarType registered for class models.User]"
Here is my query:
String sql = "UPDATE product_release SET lastedited_date= :id2 lastedited_user_id= :id3 WHERE id= :id1";
SqlUpdate update = Ebean.createSqlUpdate(sql);
update.setParameter("id1", productReleaseId);
update.setParameter("id2", currentDate);
update.setParameter("id3", currentUser);
int modifiedCount = update.execute();
The current User is retrieved using the following method:
public static User findCurrentUser() {
String currentUserTgi = Context.current().session().get(Constants.TGI);
return User.find.where().eq(Constants.TGI, currentUserTgi).findUnique();
}
And here is the beginning of User class:
@Entity
public class User extends Model implements Subject{
@Id
public Long id;
@Required
@Column(unique=true)
public String tgi;
@Required
public String firstName;
@Required
public String lastName;
@ManyToMany
public List<SecurityRole> roles;
public User(String tgi) {
this.tgi = tgi;
}
public static User.Finder<Long, User> find = new User.Finder<Long, User>(Long.class, User.class);
I have already looked on the internet, but unfortunately I did not find any solution... The closest one would be this StackOverflow question but it concerns a specific problem with Enum values.
Any ideas how I could solve this error ?
It's my first question here, so please be indulgent if I am not clear enough !
Thank you all for your help !! :-)