masterdany88
masterdany88

Reputation: 5331

playframework - package javax.persistence does not exist

I have Issue with using database I was going with this tutorial http://vimeo.com/58969923# (one from playframework.com page) in the model:

play-2.2.1/jcirs/app/models/MedicalIncident.java

public class MedicalIncident extends Model{}

I am trying to use Entity. For that I have to import: javax.persistence.* and play.db.ebean.* but none of them can be found. The error is

package javax.persistence does not exist

What should I do? Use any other database engine? Or should download some dependency. I would like to go with playframework best way. Please help.

My configuration application.conf:

 db.default.driver=org.h2.Driver
 db.default.url="jdbc:h2:mem:play"
 ebean.default="models.*"

stack trace:

[jcirs] $ run 8081

--- (Running the application from SBT, auto-reloading is enabled) ---

[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:8081

(Server started, use Ctrl+D to stop and go back to the console...)

[info] Compiling 5 Scala sources and 5 Java sources to /home/daniel/play-2.2.1/jcirs/target/scala-2.10/classes...
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:4: error: package javax.persistence does not exist
[error] import javax.persistence.*;
[error] ^
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:6: error: package play.db.ebean does not exist
[error] import play.db.ebean.*;
[error] ^
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:14: error: cannot find symbol
[error] public class MedicalIncident extends Model {
[error]                                      ^
[error]   symbol: class Model
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:13: error: cannot find symbol
[error] @Entity
[error]  ^
[error]   symbol: class Entity
[error] /home/daniel/play-2.2.1/jcirs/app/models/MedicalIncident.java:15: error: cannot find symbol
[error]     @id
[error]      ^
[error]   symbol:   class id
[error]   location: class MedicalIncident
[error] /home/daniel/play-2.2.1/jcirs/app/controllers/MedicalIncident.java:21: error: cannot find symbol
[error]         MedicalIncident medical_incident = Form.form(MedicalIncident.class).bindFormRequest().get();
[error]                                            ^
[error]   symbol:   variable Form
[error]   location: class MedicalIncident
[error] 6 errors
[error] (compile:compile) javac returned nonzero exit code
[error] application - 

! @6gfjpj0cf - Internal server error, for (GET) [/] ->

play.PlayExceptions$CompilationException: Compilation error[error: package javax.persistence does not exist]
        at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfun$apply$16.apply(PlayReloader.scala:304) ~[na:na]
        at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14$$anonfun$apply$16.apply(PlayReloader.scala:304) ~[na:na]
        at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
        at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14.apply(PlayReloader.scala:304) ~[na:na]
        at play.PlayReloader$$anon$1$$anonfun$reload$2$$anonfun$apply$14.apply(PlayReloader.scala:298) ~[na:na]
        at scala.Option.map(Option.scala:145) ~[scala-library.jar:na]
[warn] play - No application found at invoker init

Upvotes: 3

Views: 13706

Answers (4)

A. Rick
A. Rick

Reputation: 752

I was having the same problem, while using a heavily modified version of Eclipse Neon.
The clue to solving it for me, was that the only place I was seeing the errors was during a Maven build. The Eclipse IDE was able to compile and run the program just fine.
I was able to solve it by adding a couple of dependencies to the project's pom.xml file. See below for the xml code for the dependencies.
I was able to get the groupId's and artifactId's versions by drilling down the directories out on Maven Central. I just walked the tree until I found the metadata.xml files for the persistence.core and the persistence.jpa artifacts.

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.core</artifactId>
        <version>2.6.4</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.jpa</artifactId>
        <version>2.6.4</version>
        <scope>compile</scope>
    </dependency>

Upvotes: 0

victorf
victorf

Reputation: 1048

I had the same problem and I was using Eclipse. I included @Entity, e.g. and in my project console I typed eclipse with-source=true. After a "Refresh" in my Eclipse project and a "Clean", it brings me all JARs and then I clicked on the issue and the IDE offered the possibility to include javax.persistence.*, play.db.ebean.Model, etc.

Upvotes: 0

Ruslans Uralovs
Ruslans Uralovs

Reputation: 1142

Have you updated your project dependencies in Build.scala? Not sure if anything has changed in Play 2.2.1 but for Play 2.1.3 dependencies in Build.scala would look like this:

  val appDependencies = Seq(
    javaCore,
    javaJdbc,
    javaEbean
  )

EDIT: Once you update your dependencies in Build.scala don't forget to update dependencies in your IDEA or Eclipse by running corresponding play command, e.g.

play idea

Upvotes: 3

cahen
cahen

Reputation: 16636

Playframework is generating the IDEA specific files when you run "play idea" (if you're using Eclipse, run "play eclipse"). If you imported the project in the same way the tutorial explained, you should have the necessary JARs already available in the project.

If it's still not working, verify if IDEA correctly assigned a JDK to your project.

Try to understand what this framework is doing under the hood, don't just try to make it work and ignore the important stuff.

Upvotes: 0

Related Questions