I'm using playframework 2.2.1 with scala 2.10 and SORM 0.3.10 for mysql db. When I'm trying to save instance of simple case class:
case class User(email: String, password: String, token: String, verified: Boolean = false, atoken: UserAuthToken) {
def save = Db.save[User](this)
}
I'm gettin this error:
sorm.core.SormException: Attempt to refer to an unpersisted entity: UserAuthToken(7779235c1fd045f39ced7674a45baaa2,1387039847)
What I'm doing wrong? UserAuthToken
is quite simple too:
case class UserAuthToken(token: String = UUID.randomUUID().toString.replace("-",""), expire: Int = (Calendar.getInstance().getTimeInMillis/1000).toInt + 60*60*365)
Both classes are registered as entities in Db object.
UserAuthToken
is an entity, meaning that it is mapped to some row in DB. For both you and SORM to be able to identify that row (and the entity), theDb.save(..)
method returns a value of typeUserAuthToken with Persisted
, i.e. a copy of the original value with the identification information.User
is an entity too, but it refers toUserAuthToken
, meaning that the row it is mapped to must store the identification info onUserAuthToken
. So for you to be able to persist a value of typeUser
, it must refer only to an already persistedUserAuthToken
. I.e.: