fwbrasil / activate

Abandoned: Pluggable persistence in Scala
GNU Lesser General Public License v2.1
299 stars 46 forks source link

NullPointerException when querying an entity's transient val #109

Closed alcarvalho closed 10 years ago

alcarvalho commented 10 years ago

I have the following entities:

trait User extends Entity {
  @transient val userLogin: String
  val email: String
  val passwordHash: String
  val name: String
}

case class Specialist(email: String, @transient password: String, name: String, cpf: String) extends User {
  @transient override val userLogin = email
  override val passwordHash = User.hashPassword(userLogin, password)
}

// And the following query:
object User {
  def authenticate(login: String, password: String)(implicit ctx: TransactionalExecutionContext): Future[User] = {
    asyncSelect[User].where(_.userLogin :== login, _.passwordHash :== hashPassword(login, password)) map {
      case List(user) => user
      case _ => throw new AuthenticationError
    }
  }
}

When I use the "authenticate" function from User object, I get the following exception, only if I use a non memory persistence. In this case, postgresql-async:

java.lang.NullPointerException
    at net.fwbrasil.activate.statement.StatementEntitySourcePropertyValue.entityValue(StatementValue.scala:133)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDml(QlIdiom.scala:299)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDml(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDmlSelect(QlIdiom.scala:261)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDmlSelect(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDml(QlIdiom.scala:251)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDml(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDml(QlIdiom.scala:331)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDml(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDml(QlIdiom.scala:290)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDml(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDml(QlIdiom.scala:325)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDml(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$$anonfun$toSqlDml$5.apply(QlIdiom.scala:319)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$$anonfun$toSqlDml$5.apply(QlIdiom.scala:319)
    at scala.Option.map(Option.scala:145)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDml(QlIdiom.scala:318)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDml(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDmlQueryString(QlIdiom.scala:181)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDmlQueryString(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDml(QlIdiom.scala:174)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDml(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.idiom.QlIdiom$class.toSqlDml(QlIdiom.scala:169)
    at net.fwbrasil.activate.storage.relational.idiom.postgresqlDialect$.toSqlDml(PostgresqlDialect.scala:34)
    at net.fwbrasil.activate.storage.relational.async.AsyncPostgreSQLStorage$$anonfun$queryAsync$1.apply(AsyncPostgreSQLStorage.scala:66)
    at net.fwbrasil.activate.storage.relational.async.AsyncPostgreSQLStorage$$anonfun$queryAsync$1.apply(AsyncPostgreSQLStorage.scala:66)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
    at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
    at net.fwbrasil.radon.transaction.TransactionalExecutionContext$$anon$1$$anonfun$run$1.apply$mcV$sp(TransactionContext.scala:91)
    at net.fwbrasil.radon.transaction.TransactionalExecutionContext$$anon$1$$anonfun$run$1.apply(TransactionContext.scala:91)
    at net.fwbrasil.radon.transaction.TransactionalExecutionContext$$anon$1$$anonfun$run$1.apply(TransactionContext.scala:91)
    at net.fwbrasil.radon.transaction.TransactionManager.runInTransaction(TransactionManager.scala:53)
    at net.fwbrasil.radon.transaction.Required.execute(Propagation.scala:21)
    at net.fwbrasil.radon.transaction.TransactionContext$class.transactional(TransactionContext.scala:45)
    at preavs.services.MyActivateContext$.transactional(MyActivateContext.scala:14)
    at net.fwbrasil.radon.transaction.TransactionContext$class.transactional(TransactionContext.scala:35)
    at preavs.services.MyActivateContext$.transactional(MyActivateContext.scala:14)
    at net.fwbrasil.radon.transaction.TransactionContext$class.transactional(TransactionContext.scala:32)
    at preavs.services.MyActivateContext$.transactional(MyActivateContext.scala:14)
    at net.fwbrasil.radon.transaction.TransactionalExecutionContext.transactional(TransactionContext.scala:97)
    at net.fwbrasil.radon.transaction.TransactionalExecutionContext$$anon$1.run(TransactionContext.scala:90)
    at scala.concurrent.impl.ExecutionContextImpl$$anon$3.exec(ExecutionContextImpl.scala:107)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)