2012-06-18 37 views
2

刷新數據在pom.xml我已經(從http://struberg.wordpress.com/2012/05/10/using-jpa-in-real-projects-part-1/拍攝):傳遞的JDBC URL到OpenJPA - Maven的插件PostgreSQL裏

<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> 

出於某種原因,該網址是不正確過去了,我得到

目標執行增強器org.apache.openjpa:openjpa-maven-plugin:2.2.0:sql失敗:無法獲取驅動程序類「org.postgresql.Driver」和URL「null」的連接。您可能指定了無效的網址。 (org.apache.openjpa:OpenJPA中,Maven的插件:2.2.0:SQL:增強劑爲:工藝類)

我試過在connectionPropertiesurl更換jdbcUrlURL等沒有什麼幫助。不過,我可以把網址中persistence.xml確實工作:

<property name="javax.persistence.jdbc.url" 
    value="jdbc:postgresql://myURL" /> 

驅動程序,用戶和密碼從Maven的性能得到。但是,由於此URL僅用於生成DDL(在運行時以不同方式創建數據源),因此我寧願在pom.xml中也使用它,而不會污染persistence.xml。有沒有辦法做到這一點?

回答

2

我用的commons-DBCP BasicDataSource爲獲得這樣的連接:

<connectionDriverName>org.apache.commons.dbcp.BasicDataSource</connectionDriverName> 
<connectionProperties> 
    driverClassName=${database.driver.name}, 
    url=${database.connection.url}, 
    username=${database.user}, 
    password=${database.password}, 
</connectionProperties>