在pom.xml
我有(取自http://struberg.wordpress.com/2012/05/10/using-jpa-in-real-projects-part-1/):
<properties>
<openjpa.sql.action>refresh</openjpa.sql.action>
<database.driver.name>org.postgresql.Driver</database.driver.name>
<database.connection.url>jdbc:postgresql://myURL</database.connection.url>
<database.user>user</database.user>
<database.password>password</database.password>
</properties>
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>${openjpa-version}</version>
<configuration>
<includes>**/entity/*.class</includes>
<excludes>**/entity/Q*.class</excludes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
<sqlAction>${openjpa.sql.action}</sqlAction>
<connectionDriverName>${database.driver.name}</connectionDriverName>
<connectionProperties>
jdbcUrl=${database.connection.url},
user=${database.user},
password=${database.password},
</connectionProperties>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
<goal>sql</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-all</artifactId>
<version>${openjpa-version}</version>
</dependency>
</dependencies>
</plugin>
由于某种原因,URL 没有正确传递,我得到了
目标 org.apache.openjpa:openjpa-maven-plugin:2.2.0:sql 的执行增强器失败:无法为驱动程序类“org.postgresql.Driver”和 URL“null”获取连接。您可能指定了无效的 URL。(org.apache.openjpa:openjpa-maven-plugin:2.2.0:sql:enhancer:process-classes)
我试过用 , 等替换in 。没有任何帮助jdbcUrl
。但是,我可以输入 URL ,这确实有效:connectionProperties
url
URL
persistence.xml
<property name="javax.persistence.jdbc.url"
value="jdbc:postgresql://myURL" />
驱动程序、用户和密码是从 Maven 属性中获取的。但是,由于此 URL 仅用于生成 DDL(数据源在运行时以不同的方式创建),因此我更希望将它也放入其中pom.xml
而不会污染persistence.xml
. 有没有办法做到这一点?