【问题标题】:Play 2.3 package JPA is missing播放 2.3 包 JPA 丢失
【发布时间】:2015-02-02 15:16:51
【问题描述】:

我使用 play 2.3.6 和 JPA ORM 处理数据,所以我遵循 playframework (https://www.playframework.com/documentation/2.3.x/JavaJPA) 的文档,但我不知道为什么包 play.db.jpa 没有导入到我的项目中。

我尝试清理我的项目(激活器清理、激活器清理文件)但没有任何改变

错过什么才能正常工作???

下面是我的配置:

build.sbt

name := "play_sample1"

version := "1.0"


libraryDependencies ++= Seq(  
  javaJdbc,  
  cache,
  javaWs,
  javaJpa,
  "org.hibernate" % "hibernate-entitymanager" % "4.3.6.Final",  
  "mysql" % "mysql-connector-java" % "5.1.18"
)

lazy val root = (project in file(".")).enablePlugins(PlayJava) 
                    .aggregate(common, webstats)  
                    .dependsOn(common, webstats)                 

lazy val core = (project in file("modules/core")).enablePlugins(PlayJava)

lazy val common = (project in file("modules/common")).enablePlugins(PlayJava).dependsOn(core)
lazy val webstats = (project in file("modules/webstats")).enablePlugins(PlayJava).dependsOn(common)

appplication.conf

# This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
#
# This must be changed for production, but we recommend not changing it in this file.
#
# See http://www.playframework.com/documentation/latest/ApplicationSecret for more details.
application.secret="yIX1uonulRO^O8A56tlkb1c4aJS^@9k<dr@^mDXuSBXggKHMRJykv@>``Ra?yh<i"

# The application languages
# ~~~~~
application.langs="en"

# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
# application.global=Global

# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `conf/my.application.Router`,
# you may need to define a router file `my.application.routes`.
# Default to Routes in the root package (and `conf/routes`)
# application.router=my.application.Routes

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/play_test"
db.default.user=root
db.default.password=""

jpa.default=defaultPersistenceUnit
db.default.jndiName=DefaultDS

# You can expose this datasource via JNDI if needed (Useful for JPA)
# db.default.jndiName=play_test

# Evolutions
# ~~~~~
# You can disable evolutions if needed
# evolutionplugin=disabled

# Ebean configuration
# ~~~~~
# You can declare as many Ebean servers as you want.
# By convention, the default server is named `default`
#
# ebean.default="models.*"

# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/),
# by providing an application-logger.xml file in the conf directory.

# Root logger:
logger.root=ERROR

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

/conf/META-INF/persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"  
version="2.0">  
  <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">  
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>DefaultDS</non-jta-data-source>  
    <properties>  
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />  
        <property name="hibernate.hbm2ddl.auto" value="update"/>
        <property name="hibernate.show_sql" value="true"></property>
        <property name="hibernate.format_sql" value="true"></property>
    </properties>  
  </persistence-unit>  
</persistence>

【问题讨论】:

  • 您需要添加 JPA、hibernate 和 mysql 作为使用它们的子项目的依赖项,而不是在顶级项目中。因此,在您的情况下,如果您在 core 和 common 中使用 JPA.em(),则需要将其添加为 core/build.sbt 中的依赖项(因为 common 取决于 core,所以那里不需要)。这同样适用于 xml 文件...
  • 尝试在javaJdbc 之后移动javaJpa 然后activator clean 然后尝试导入

标签: hibernate jpa playframework packages


【解决方案1】:

尝试删除 javaJdbc 依赖项。

希望对你有帮助!

【讨论】:

    【解决方案2】:

    我已经尝试删除 javaJdbc 但没有更改。我通过使用上面相同的配置文件创建一个新项目解决了我的问题。包裹没有丢失

    【讨论】:

      猜你喜欢
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      • 2016-07-04
      • 2015-11-10
      • 1970-01-01
      相关资源
      最近更新 更多