如何使用JPA插件在Play Framework 2中获得org.hibernate.cfg.Configuration

如何使用JPA插件在Play Framework 2中获得org.hibernate.cfg.Configuration,hibernate,playframework-2.0,Hibernate,Playframework 2.0,我可以像这样获得JPA配置: Configuration jpaConf = Configuration.root().getConfig("jpa"); <?xml version="1.0" encoding="UTF-8"?> <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-insta

我可以像这样获得JPA配置:

Configuration jpaConf = Configuration.root().getConfig("jpa");
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
  <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <non-jta-data-source>DefaultDS</non-jta-data-source>
    <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.use_sql_comments" value="true"/>
            <!--<property name="hibernate.default_schema" value="&quot;legalEntitiesTest&quot;"/>-->
            <property name="hibernate.globally_quoted_identifiers" value="false"/>
        </properties>
  </persistence-unit>
</persistence>
但是我如何获得org.hibernate.cfg.Configuration,我需要它来进行类似于这个问题的模式导出(基于Play Framework 1):

My Play Framework 2.x application.conf具有以下功能:

# Database configuration
# ~~~~~
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/dpma"
db.default.user=bp
db.default.jndiName=DefaultDS
jpa.default=defaultPersistenceUnit
my persistence.xml如下所示:

Configuration jpaConf = Configuration.root().getConfig("jpa");
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
  <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <non-jta-data-source>DefaultDS</non-jta-data-source>
    <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.use_sql_comments" value="true"/>
            <!--<property name="hibernate.default_schema" value="&quot;legalEntitiesTest&quot;"/>-->
            <property name="hibernate.globally_quoted_identifiers" value="false"/>
        </properties>
  </persistence-unit>
</persistence>

默认值

**对于不熟悉Play Framework的用户:*

您可以使用hibernate配置文件自己创建hibernate配置对象:

Configuration c = new Configuration();
c.configure("path to hibernate config").getProperty("hibernate property");
如果不使用hibernate cfg文件,则可以通过这种方式将JPA实体添加到配置中(它假定所有JPA类都属于一个包)


请详细说明你的代码片段。代码只能回答像“试试这个”这样的问题,这样的尝试不会有帮助anyone@poornerd如何配置持久性提供程序?@MonCalamari我刚刚更新了描述。您以前使用过Play Framework吗?我真正想做的是能够在我的Global.java中进行hibernate模式验证。为了做到这一点,我需要Hibernate配置。我之所以需要它,是因为我想使用进化,但仍然想验证模式。