0

我想使用纯 JPA 2 创建一个动态时间表。就像在休眠中一样,我们使用 SchemaExport 创建动态表。

编码:

<properties>
    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/employee;create=true"/>
    <property name="javax.persistence.jdbc.user" value="root"/>
    <property name="javax.persistence.jdbc.password" value="root"/>
    <property name = "hibernate.show_sql" value = "true" />
<properties>

我使用时发生以下异常create=true

WARN: HHH000342: Could not obtain connection to query metadata : Unknown database 'employee;create=true'
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: EmployeeService] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
4

1 回答 1

0

您可以create=truepersistence.xmlurl 中指定。

 <persistence-unit name="PU" transaction-type="RESOURCE_LOCAL">
     ...
    <properties>
      ---
      <property name="javax.persistence.jdbc.url" 
          value="jdbc:???://localhost:port/DBName;create=true"/>
      <property name="javax.persistence.jdbc.user" value="user"/>
      <property name="javax.persistence.jdbc.password" value="pwd"/>
    </properties>
  </persistence-unit>
</persistence>
于 2013-01-02T12:56:01.650 回答