score:5
Accepted answer
I found the solution thanks this link : http://www.avaje.org/topic-137.html
import javax.persistence._
import play.db.ebean._
import play.data.validation.Constraints._
import scala.collection.JavaConverters._
@Entity
@Table( name="Task" )
class Task{
@Id
var id:Int = 0
@Column(name="title")
var label:String = null
}
/**
* Task Data Access Object.
*/
object Task extends Dao(classOf[Task]){
def all(): List[Task] = Task.find.findList().asScala.toList
def create(label: String) {
var task = new Task
task.label = label
Task.save(task)
}
def delete(id: Long) {
Task.delete(id)
}
}
And the DAO :
/**
* Dao for a given Entity bean type.
*/
abstract class Dao[T](cls:Class[T]) {
/**
* Find by Id.
*/
def find(id:Any):T = {
return Ebean.find(cls, id)
}
/**
* Find with expressions and joins etc.
*/
def find():com.avaje.ebean.Query[T] = {
return Ebean.find(cls)
}
/**
* Return a reference.
*/
def ref(id:Any):T = {
return Ebean.getReference(cls, id)
}
/**
* Save (insert or update).
*/
def save(o:Any):Unit = {
Ebean.save(o);
}
/**
* Delete.
*/
def delete(o:Any):Unit = {
Ebean.delete(o);
}
Source: stackoverflow.com
Related Query
- How to create an instance of a model with the ebean framework and scala in Play 2.2
- How do you read the HTML content of an Atom feed with Scala and Play framework 2.0?
- How to use IntelliJ with Play Framework and Scala
- How do I get Intellij IDEA 12.0 to work with Play Framework 2.1.0 app and Scala 2.10.0?
- How to create a Scala class with private field with public getter, and primary constructor taking a parameter of the same name
- How to show images using Play framework and Scala in the view page
- How to read and write Anorm object with the new JSON API in Play Framework 2.1-RC2?
- Does Play Framework with the Scala plugin support MVC and the Java API?
- How to fetch records from the database using Play with Scala and Slick
- How to create OFormat from Format in scala and play framework
- How to send email with attached file in scala and play framework (2.3.9) using activator?
- Create a 2d html5 click and play game with scala and play2 framework or playN?
- Best practices to separate business logic from the Controller to the Model layer with Play framework + Scala + Slick
- How to use Memcached with the Scala Play Framework 2.2?
- How can I create a submit button with parameter in the play framework
- How to organise the entity model for play framework 2 when working with anorm
- How do I create a periodic Poller with Play 2.0 and Scala
- Play Framework 2.4.1 One form with two buttons. Which button was pressed? And how do I get the input data?
- How to log user credentials when authentication fails with Scala Play Framework and Silhouette
- How to log user credentials when authentication fails with Scala Play Framework and Silhouette
- With play and akka-https: How to properly chain multiple requests to the incoming request to create a response?
- How to get current day of the week and used it in scala template in Play framework
- How to use cdn url with play framework and scala for image display?
- How to synchronize Play framework 2 with MongoDB and the steps to be followed
- Which is best data access options available for Play framework with Scala and PostgreSQL?
- Dynamic SQL Parameters with Anorm and Scala Play Framework
- How to get Scala imports working in IntelliJ IDEA with the Play framework?
- How to create a global variable with Play Framework 2.0
- Debug not working with play framework activator, scala and eclipse
- How to set up play framework ApplicationLoader and Macwire to work with custom routes?
More Query from same tag
- Parsing an array of json objects to scala objects with pickling
- How to test Camel using ScalaTest
- Scala Subclass change return type without override
- String seen as a Monoid
- How to configure GitLab CI job for running Gatling tests integrated with sbt?
- How to compare a column with the columns in the same dataframe in apache spark
- Can scalatags be used together with binding.scala?
- Update Map type columns in Cassandra with new key value pairs and not completely overwrite the map
- Handle exception in Play2.5/scala controller
- Querying Elasticsearch large index from spark
- Comparing dates when using reduceByKey
- How to prevent Intellij from treating Scala warning as error?
- Run SBT 1.2.8 project with Java -D options on Windows
- Scala - Check if a class is imported or not
- Direct operations on off-heap arrays
- java.lang.StackOverflowError on IntelliJ
- How can I log in Play Framework using Scala?
- Spark Scala Int vs Integer for Option vs StructType
- Column type not defined while upgrading from slick 2.1 to slick 3.2 in scala
- How to convert mutable.Map to mutable.HashMap in Scala?
- In spark structured streaming, is there a way to sleep the read operation during maintenance window for the database
- Concatenate different Json values into a single response with Scala Play
- Spark/Scala : Spark DataFrame column with Struct Type
- Is it possible to store a function that is yet to be defined in a variable in Scala?
- "datasource not a member of org.apache.phoenix" when trying to Save DataFrames to Phoenix using DataSourceV2
- Why return type for func1 is Unit whereas for func2 is Int ?
- Create dynamic query from the Dataframe present in Spark Scala
- Prepend header record (or a string / a file) to large file in Scala / Java
- Apache POI: Why Is a Row Missing When I use shiftRows?
- How to set initial value for foldLeft When Using EitherT[Future, Failure, Option[B]]