简体   繁体   中英

SBT in Play Framework can't find org.hibernate dependencies

When I try to implement Hibernate in to a Play Framework 2 application, then it can't find the org.hibernate library.

[error] /home/cc/Desktop/eclipses/workspace/muell/app/controllers/HibernateUtil.java:3: error: package org.hibernate does not exist
[error] import org.hibernate.Session;
[error]                     ^
[error] /home/cc/Desktop/eclipses/workspace/muell/app/controllers/HibernateUtil.java:4: error: package org.hibernate does not exist
[error] import org.hibernate.SessionFactory;  
[error]                     ^
[error] /home/cc/Desktop/eclipses/workspace/muell/app/controllers/HibernateUtil.java:5: error: package org.hibernate.cfg does not exist
[error] import org.hibernate.cfg.Configuration;
... and so on ...

Here is the build.sbt

name := "muell"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  "mysql" % "mysql-connector-java" % "5.1.18"
)     

val appDependencies = Seq(
    "org.hibernate" %% "hibernate-core" % "4.2.6.Final",
    "org.hibernate" %% "hibernate-entitymanager" % "3.6.9.Final",
    "org.hibernate.javax.persistence" %% "hibernate-jpa-2.0-api" % "1.0.0.Final"
)

play.Project.playJavaSettings

Here is the plugins.sbt

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

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += "Primary Maven Repository" at "http://repo1.maven.org/maven2/"

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

This works for me play framework 2.2.1, I think that it should work in 2.2.0,

The problem is that you are adding dependencies for the scala version with %%, and this is only for java, you can use with scala of course.

And since it is a maven repository you do not need to spicify it as a resolver.

This is the content of my build.sbt:

name := "testHibernate"

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  jdbc,
  anorm,
  cache,
  "org.hibernate" % "hibernate-core" % "4.3.0.CR1",
  "org.hibernate" % "hibernate-entitymanager" % "4.3.0.CR1",
  "org.hibernate.javax.persistence" % "hibernate-jpa-2.1-api" % "1.0.0.Draft-16"
)     

play.Project.playScalaSettings

If you want to change the hibernate version go to

http://search.maven.org/#search|ga|1|hibernate and remember to change that file with:

"groupId" % "artifactId" % "version"

if exist an adapted scala version in play framework explains it:

Getting the right Scala version with %%

If you use groupID %% artifactID % revision instead of groupID % artifactID % revision (the difference is the double %% after the groupID), sbt will add your project's Scala version to the artifact name. This is just a shortcut.

I hope that it will hep you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM