2014-11-21 42 views
0

我建立一个使用h2数据库的应用程序,我persistence.xml如何设置一个可移植的persistence.xml文件?

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> 
    <persistence-unit name="taskUnit" transaction-type="RESOURCE_LOCAL"> 
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
     <class>com.github.tarrsalah.jersey.todo.app.model.Task</class> 
     <properties>   
      <property name="javax.persistence.jdbc.url" value="jdbc:h2:file:/home/tarrsalah/src/github.com/tarrsalah/jaxrs-todo-app/target/todo"/> 
      <property name="javax.persistence.jdbc.user" value=""/> 
      <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/> 
      <property name="javax.persistence.jdbc.password" value=""/> 
     </properties> 
    </persistence-unit> 
</persistence> 

正如你可以看到我有javax.persistence.jdbc.url属性设置为本地h2数据库中的硬链接,我想分享在github上我的代码。

如何在不更改persistence.xml配置文件的情况下制作我的代码的克隆版本?

PS:我使用的数据库迁移迁徙路线)

回答

1

为了与他人分享这个代码,你可以尝试使用内存数据库H2

<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=1000"/> 
+0

如何飞路迁移? – tarrsalah 2014-11-21 04:56:47

+0

AFAIK飞路迁移工作在h2内存数据库中。看看这里http://stackoverflow.com/questions/21019874/table-not-found-after-apparently-successful-migration – Shailendra 2014-11-21 05:03:21

+0

@Shailendar迁移成功使用maven flyway插件,但似乎eclipseLink无法找到它(我使用相同的URL)。 – tarrsalah 2014-11-21 05:10:11