Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find the entity 'id' property for class #181

Open
cocodrino opened this issue Jun 28, 2015 · 0 comments
Open

Can't find the entity 'id' property for class #181

cocodrino opened this issue Jun 28, 2015 · 0 comments

Comments

@cocodrino
Copy link

Hi, I;m receiving an error and it;s not clear for me because I think than my code is pretty similar to the sample provider in the documentation

this is the error

$ sbt run
[info] Loading global plugins from /home/yo/.sbt/0.13/plugins
[info] Set current project to MyProject (in build file:/home/yo/Downloads/proj/scalaPROJ/dbprueba/)
[info] Compiling 1 Scala source to /home/yo/Downloads/proj/scalaPROJ/dbprueba/target/scala-2.10/classes...
[info] Running dbsample.Base 
22:02:28.405 [run-main-0] DEBUG org.reflections.Reflections - going to scan these urls:
    jar:file:/home/yo/.ivy2/cache/net.fwbrasil/activate-core_2.10/jars/activate-core_2.10-1.6.jar!/
    file:/home/yo/Downloads/proj/scalaPROJ/dbprueba/target/scala-2.10/classes/

22:02:28.753 [run-main-0] INFO  org.reflections.Reflections - Reflections took 343 ms to scan 2 urls, producing 43 keys and 813 values 
22:02:28.795 [run-main-0] DEBUG org.reflections.Reflections - going to scan these urls:
    jar:file:/home/yo/.ivy2/cache/net.fwbrasil/activate-core_2.10/jars/activate-core_2.10-1.6.jar!/
    jar:file:/home/yo/.ivy2/cache/net.fwbrasil/activate-prevalent_2.10/jars/activate-prevalent_2.10-1.6.jar!/
    jar:file:/home/yo/.ivy2/cache/net.fwbrasil/activate-prevayler_2.10/jars/activate-prevayler_2.10-1.6.jar!/
    file:/home/yo/Downloads/proj/scalaPROJ/dbprueba/target/scala-2.10/classes/
    jar:file:/home/yo/.ivy2/cache/net.fwbrasil/activate-jdbc_2.10/jars/activate-jdbc_2.10-1.6.jar!/

22:02:29.201 [run-main-0] INFO  org.reflections.Reflections - Reflections took 405 ms to scan 5 urls, producing 153 keys and 3555 values 
[error] (run-main-0) java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
    at dbsample.Base$delayedInit$body.apply(Base.scala:9)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at dbsample.Base$.main(Base.scala:8)
    at dbsample.Base.main(Base.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
Caused by: java.lang.IllegalStateException: Can't find the entity 'id' property for class dbsample.Person, probably the entity class was loaded before the persistence context. Try to add a 'transactional{}' call on the application startup to force the persistence context load.Please also make sure that there aren't instance variables or methods referencing entities inside the main class.
    at net.fwbrasil.activate.entity.EntityMetadata$$anonfun$11.apply(EntityMetadata.scala:46)
    at net.fwbrasil.activate.entity.EntityMetadata$$anonfun$11.apply(EntityMetadata.scala:46)
    at scala.Option.getOrElse(Option.scala:120)
    at net.fwbrasil.activate.entity.EntityMetadata.<init>(EntityMetadata.scala:45)
    at net.fwbrasil.activate.entity.EntityHelper$$anonfun$initialize$1.apply(EntityHelper.scala:47)
    at net.fwbrasil.activate.entity.EntityHelper$$anonfun$initialize$1.apply(EntityHelper.scala:43)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at net.fwbrasil.activate.entity.EntityHelper$.initialize(EntityHelper.scala:43)
    at net.fwbrasil.activate.entity.id.EntityIdContext$class.$init$(EntityId.scala:109)
    at dbsample.Context$.<init>(Context.scala:9)
    at dbsample.Context$.<clinit>(Context.scala)
    at dbsample.Base$delayedInit$body.apply(Base.scala:9)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.App$$anonfun$main$1.apply(App.scala:71)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.App$class.main(App.scala:71)
    at dbsample.Base$.main(Base.scala:8)
    at dbsample.Base.main(Base.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
[trace] Stack trace suppressed: run last compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
    at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last compile:run for the full output.
[error] (compile:run) Nonzero exit code: 1
[error] Total time: 16 s, completed Jun 27, 2015 10:02:29 PM

my code is really simple..this is the context file

package dbsample

import net.fwbrasil.activate.ActivateContext
import net.fwbrasil.activate.storage.relational.PooledJdbcRelationalStorage
import net.fwbrasil.activate.storage.relational.idiom.h2Dialect



object Context extends ActivateContext {

   val storage = new PooledJdbcRelationalStorage {
      val jdbcDriver = "org.h2.Driver"
      val user = Some("sa")
      val password = Some("")
      val url = "jdbc:h2:mem:my_database;DB_CLOSE_DELAY=-1"
      val dialect = h2Dialect
   }



}

this...the migration

package dbsample


import net.fwbrasil.activate.migration.Migration
import Context._

class CreatePersonTableMigration extends Migration {
   def timestamp = 2012111616051L
   def up = {
      table[Person]
        .createTable(
           _.column[String]("name"))
   }
}

and the last one is the main code

package dbsample

import dbsample.Context._

class Person( var name: String) extends Entity


object Base extends App {
   transactional{}

   transactional {
      new Person("John")
   }

   val john = transactional {
      select[Person].where(_.name :== "John").head
   }

   transactional {
      john.name = "John Doe"
   }

   transactional {
      all[Person].foreach(println)
   }
}

can you notice something bad here?..

thank you so much!!...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant