I worked before with Playframework 2.1.2. Now I tried to work with the latest version. I tried to import the play.db.ebean.Model like in 2.1.2 but it didn't work. Then I found that this was replaced by com.avaje.ebean.Model. But in the jdk 1.8.0_45 there is no package com.avaje...
I believe that I have made an absolute stupid mistake but I can't see it... How do I set up Play to work with Ebean?
Thanks
Ok, you are using Play 2.4.6. Did you read the JavaEbean documentation? The docs are pretty clear in my opinion.
Steps:
To enable it, add the Play Ebean plugin to your SBT plugins in project/plugins.sbt:
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
And then modify your build.sbt to enable the Play Ebean plugin:
lazy val myProject = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
Specify where your models live in the application.conf:
ebean.default = ["models.*"]
After this run a ./activator clean run. This will update and download all needed dependencies including Ebean dependencies!
After that create your model like:
package models;
import java.util.*;
import javax.persistence.*;
import com.avaje.ebean.Model;
import play.data.format.*;
import play.data.validation.*;
@Entity
public class Task extends Model {
@Id
@Constraints.Min(10)
public Long id;
@Constraints.Required
public String name;
public boolean done;
@Formats.DateTime(pattern="dd/MM/yyyy")
public Date dueDate = new Date();
public static Finder<Long, Task> find = new Finder<Long,Task>(Task.class);
}
I had the same problem and was absolutely racking my brain for hours! I followed the documentation carefully and then tried a bunch of different combinations that didn't work. Anyway...
If you're using Eclipse (I'm just assuming), try running activator eclipse on the command line. It will add the play-ebean.jar to .classpath so Eclipse knows where it is. Then, make sure you refresh the project in Eclipse. play-ebean.jar should appear under Referenced Libraries and you'll be able to import com.avaje.ebean.* into your model classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With