Configure QueryDSL on Play 2 Framework

柔情痞子 提交于 2019-12-05 18:44:01

I just got it working using play-querydsl with Play 2.2.2. I followed the instructions (using 0.1.1 as the version number in plugins.sbt instead of 0.1.0) and it generated the Q* model classes to target/scala-2.10/src_managed/main/querydsl. I use Eclipse, so I ran play eclipse to include this folder in the classpath.

I tried to get the APT annotation compiling to work directly in Eclipse but gave up on that.

As a side note, I compared QueryDSL and EasyCriteria and I found EasyCriteria easier to use because it more closely mirrors the user-friendly queries of Ebean. However, if you want type safety, QueryDSL is definitely better than JPA's built-in criteria API.

plugins.sbt (Play 2.2.2):

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.2")

addSbtPlugin("com.code-troopers.play" % "play-querydsl" % "0.1.1")

build.sbt (Play 2.2.2):

name := "project"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  javaJdbc,
  javaJpa.exclude("org.hibernate.javax.persistence", "hibernate-jpa-2.0-api"),
  cache,
  filters,
  "org.hibernate" % "hibernate-entitymanager" % "4.3.5.Final",
  "com.mysema.querydsl" % "querydsl-jpa" % "3.3.4",
  "postgresql" % "postgresql" % "9.1-901-1.jdbc4",
  "org.mindrot" % "jbcrypt" % "0.3m",
  "net.sf.opencsv" % "opencsv" % "2.3"
)     

play.Project.playJavaSettings

playJavaSettings ++ QueryDSLPlugin.queryDSLSettings

val current = project.in(file(".")).configs(QueryDSLPlugin.QueryDSL)

QueryDSLPlugin.queryDSLPackage := "models"

play.Keys.lessEntryPoints <<= baseDirectory { base =>
   (base / "app" / "assets" / "stylesheets" * "*.less")
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!