【发布时间】:2015-01-22 06:12:04
【问题描述】:
我正在尝试使用 hibernate 设置 play 2.2 应用程序,但它似乎无法正常工作。我认为我拥有所有正确的文件,但是当我加载我的应用程序时,这些表不会像使用 EBEAN 时那样自动生成。这是我的文件:
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.H2Dialect"/>
</properties>
</persistence-unit>
</persistence>
build.sbt
name := "listr"
version := "1.0-SNAPSHOT"
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
javaJpa,
"org.hibernate" % "hibernate-core" % "4.2.3.Final",
"org.hibernate" % "hibernate-entitymanager" % "4.2.3.Final"
)
val appDependencies = Seq(
javaJdbc
)
play.Project.playJavaSettings
conf/application.conf
# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
# db.default.user=sa
# db.default.password=""
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
将各种文件更改为上述文件后,我制作了一个简单的模型来测试它是否设置正确以及hibernate是否会自动生成表格,但似乎什么也没发生
apps/models/List.java
package models;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class List {
@Id
private long id;
private String name;
}
创建此模型后,我运行了项目,加载后检查了 h2 数据库,没有创建任何表,也没有创建进化脚本。还有什么我需要做的/我需要手动创建进化脚本吗?我认为它会像使用 E-Bean 一样自动创建。
【问题讨论】:
标签: java hibernate orm playframework playframework-2.0