由于URL无效,Liberty 8.5.5.3配置文件中的OpenJPA PersistenceException

时间:2014-10-21 14:26:16

标签: openjpa websphere-liberty

我刚刚在" server.xml"中配置DB2 JCC属性时发现了一个令人讨厌的错误。我想与你分享我的Liberty Profile v8.5.5.3,因为我花了很长时间在网上搜索有用的提示。

我在" server.xml"中配置了一个用于JPA访问的DB2数据源。使用Eclipse Luna中的Liberty Developer Tools(设计选项卡):" DB2 JCC Properties"在我看来,并没有很清楚地排序。所需的数据库用户名和密码不会彼此相邻,这使我很难识别正确的属性。遗憾的是,我在字段"客户用户"中输入了数据库用户名。而不是"用户"它几乎位于列表的末尾。 抛出的异常是:

<openjpa-2.2.3-SNAPSHOT-r422266:1595313 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-2.2.3-SNAPSHOT-r422266:1595313 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "null" and URL "null".  You may have specified an invalid URL.
at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:255)
at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:241)
at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:733)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:94) ...    ... at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1176)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:795) Caused by: java.sql.SQLNonTransientException: [jcc][t4][10205][11234][4.18.60] Null userid is not supported. ERRORCODE=-4461, SQLSTATE=42815 DSRA0010E: SQL State = 42815, Error Code = -4,461
at com.ibm.db2.jcc.am.kd.a(kd.java:747)}

1 个答案:

答案 0 :(得分:0)

此异常表示连接URL不正确:&#34;您可能指定了无效的网址。&#34;但是&#34;无法获得驱动程序类的连接&#39; null&#39;和URL&#39; null&#39;&#34;真的把我指向了错误的方向。

我建议使用“源”选项卡而不是Liberty配置文件配置工具中的“设计”选项卡,并手动编辑XML条目以避免可能导致混淆的错误配置值,例如

<server description="new server">
<!-- Enable features -->
<featureManager>
    <feature>jsp-2.2</feature>
    <feature>jdbc-4.0</feature>
    <feature>jpa-2.0</feature>
</featureManager>
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
<applicationMonitor updateTrigger="mbean"/>

<dataSource id="DB2Connection" jndiName="jdbc/DB2Connection">
    <jdbcDriver libraryRef="DB2jdbc4libs"/>
    <properties.db2.jcc user="Administrator" databaseName="CUSTDB" password="{xor}password" portNumber="50000" serverName="dbserver.mycompany.com"/>
</dataSource>
<library id="DB2jdbc4libs">
        <fileset caseSensitive="true" dir="/opt/db2/V10.5/java" includes="db2jcc_license_cu.jar, db2jcc.jar"/>
</library>

<webApplication id="DynWebJPASample" location="DynWebJPASample.war" name="DynWebJPASample"/>