OpenJPA PersistenceException in Liberty 8.5.5.3 Profile due to invalid URL - openjpa

I have just found an annoying mistake I made during the configuration of the DB2 JCC Properties in the "server.xml" of my Liberty Profile v8.5.5.3 which I wanted to share with you since it took me a long time searching the Web for helpful hints.
I configured a DB2 Datasource for JPA access in the "server.xml" using the Liberty Developer Tools in Eclipse Luna (Design tab): The "DB2 JCC Properties" are not sorted very clearly in my opinion. The required DB user name and password are not listed next to each other and made it hard for me to identify the correct properties. I unfortunately entered the DB user name in the field "Client User" instead of in "User" which is located nearly at the end of the list.
The thrown exception was:
<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)}

This exception indicates an incorrect connection URL: "You may have specified an invalid URL." but "A connection could not be obtained for driver class 'null' and URL 'null'" really pointed me in the wrong direction.
I recommend using the Source tab instead of the Design tab in the Liberty profile configuration tools and edit the XML entries manually to avoid wrong configuration values that may lead to confusion, e.g.
<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"/>

Related

Issue enabling jpa and jdbc in Websphere Liberty

I am following these exercises for learning Liberty.
I am having an issue in he Lab 3 - Module 2.2 Liberty and JPA (DB2) .
After setting all the JDBC and Data Source details, i restart the server and i do not see the two lines that mention the dataSource and jdbd driver.
[AUDIT] J2CA8004I : The dataSource DB2Connection is avilable as jdbc/DB2Connection.
[AUDIT] J2CA8000I : The jdbcDriver my JDBCDriver is available.
How can i know if the jpa and jdb features ae correctly set?
This is the server.xml
<!-- Enable features -->
<featureManager onError="WARN">
<feature>jsp-2.2</feature>
<feature>jpa-2.0</feature>
<feature>jdbc-4.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443" />
<jdbcDriver id="myJDBCDriver">
<library name="DB2Lib">
<fileset dir="C:\wlp\db2jdbc" includes="db2jcc4.jar, db2jcc_license_cu.jar"></fileset>
</library>
</jdbcDriver>
<dataSource jndiName="jdbc/DB2Connection" id="DB2Connection"
jdbcDriverRef="myJDBCDriver">
<properties.db2.jcc databaseName="SAMPLE" serverName="igacloud" password="{xor}FhgeOz1tPj08" user="db2admin"></properties.db2.jcc>
</dataSource>
Unlike Classic WebSphere, which has a "test connection" capability in its admin console (datasource panel), there is no equivalent means with WebSphere Liberty yet. Have you tried testing the connection with a simple "Hello World" JPA application?
The CWWKF0012I message is simply confirming what features have been enabled - some features depend on other features and automatically enables them, which is why you see more features than defined in your server.xml.

How to increase the heap size of WebSphere Application Server V8.5 Liberty Profile in Eclipse?

I have a WebSphere Application Server V8.5 Liberty Profile in eclipse. My webapp has been giving java.lang.OutOfMemoryError and thus I need to increase the heap size.
As this and this post suggested I changed the server.xml, by adding jvmEntries tag (It was not previously there):
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
<feature>localConnector-1.0</feature>
<feature>jpa-2.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to
the following element, e.g. host="*" -->
<httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint" />
<jvmEntries initialHeapSize="1024" maximumHeapSize="2048" />
<applicationMonitor updateTrigger="mbean" />
<webApplication id="app" location="app.war"
name="app" />
</server>
But eclipse shows it as an invalid tag, with following error:
cvc-complex-type.2.4.a: Invalid content was found starting with
element 'jvmEntries'. One of '{include, variable, trustAssociation,
applicationMonitor, application, classloading, basicRegistry,
bundleRepository, osgiApplication, authentication, authCache,
jaasLoginModule, jaasLoginContextEntry, cdiContainer, channelfw,
tcpOptions, library, collectiveMember, hostAuthInfo,
managedExecutorService, connectionManager, contextService,
distributedMap, enterpriseApplication, webApplication, httpDispatcher,
mimeTypes, httpEncoding, virtualHost, httpOptions,
httpAccessLogging, httpEndpoint, authData, dataSource, jdbcDriver,
jndiEntry, jpa, jspEngine, fileset, executor, featureManager, config,
customLdapFilterProperties, edirectoryLdapFilterProperties,
domino50LdapFilterProperties, netscapeLdapFilterProperties,
ldapRegistry, securewayLdapFilterProperties,
iplanetLdapFilterProperties, idsLdapFilterProperties,
activedLdapFilterProperties, logging, ltpa, ejbContainer, monitor,
oauthProvider, oauth-roles, remoteFileAccess, administrator-role,
quickStartSecurity, pluginConfiguration, webContainer, httpSession,
httpSessionDatabase, sslDefault, keyStore, ssl, sslOptions,
timedOperation, transaction, webAppSecurity, federatedRepository,
zosLogging, authorization-roles}' is expected.
How should I increase the heap size then?
Correct way to do it is to create jvm.options file in the server directory with the following content e.g.:
-Xms512m
-Xmx1024m
Check this link Customizing the Liberty profile environment
In Eclipse, in the Servers view you can right-click the server, and select New > Server Environment File > jvm.options
The Liberty profile is a bit different than the regular WebSphere profile. You will need to configure a jvm.options file per these instructions:
IBM Setting generic JVM arguments in the WebSphere Application Server V8.5 Liberty profile
Customizing the Liberty profile environment

jboss connection pool doesn't handle errors gracefully

I'm using jboss 5.0.1 with multiple data sources configured.
It seems that on startup, if one of those is configured incorrectly, jboss throws an exception and refuses to start.
I would like to know if it's possible to configure jboss to be resilient to these kind of problems.
You can configure the connections in the xml file which holds the connection parameters/mapping. In my case, i am using a microsoft sql server as the datasource, so i have to use the mssql-ds.xml file (inside the server/deploy directory) to specify:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>myTestServer</jndi-name>
<connection-url>jdbc:sqlserver://xxx.xxx.xxx.xxx:1433;databaseName=MyDB</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<user-name>test</user-name>
<password>abc123</password>
<min-pool-size>10</min-pool-size>
<max-pool-size>25</max-pool-size>
<!-- sql to call when connection is created -->
<new-connection-sql>select getdate()</new-connection-sql>
<!-- -->
<!-- sql to call on an existing pooled connection when it is obtained from pool
This will be run before a managed connection is removed from the pool
for use by a client -->
<check-valid-connection-sql>select getdate()</check-valid-connection-sql>
</local-tx-datasource>
</datasources>
This helps control the connections in the pool, and should stop dodgy deadlocks. I'm not entirely sure whether this will test the current transaction level on the connection in question, so if you want to make absolutely sure, you can try: <check-valid-connection-sql>IF ##TRANCOUNT > 0 raiserror ('%s',18,1,'Open Transactions Discovered')</check-valid-connection-sql> This will give you an explicit SQLException to handle.
But if you are getting an error on startup, it would be very useful to see what those errors are.

Connection pooling on a Tomcat 7

I am having issues with implementing connection pooling on a tomcat7.
For some reason tomcat is trying to connect with my machines username. I have been googlin it for a while now but without a luck.
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory
(FATAL: role "caspinol" does not exist)
Cant connect to db
Log In failed: An Exception has occurred! java.lang.NullPointerException
java.lang.NullPointerException
at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)...
My context.xml looks as follows:
<Resource auth="Container" name="jdbc/postgres" type="javax.sql.DataSource" user="biller" password="biller"
driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432" maxActive="150"
schema="biller" maxIdle="4"/>
And the web.xml:
<resource-ref>
<description>postgreSQL Datasource</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
I am using jdbc4.jar postgres driver.
I appreciate if somebody can have a look and point out what is the mistake
Thanks in advance
The URL seems to be wrong.
Try this URL :
jdbc:postgresql://localhost:5432/<db_name>
Replace the <db_name> with actual database name.
This is not the right solution here for the issue but would help somebody searching with the same issue with correct connection string.
Check for your network connection access:
Like connection string
jdbc:postgresql://[::1]:5432/<db_name>
uses IPv6,
This will break other connections like accessing wsdl urls from application that are available only via IPv4.
Please hava a look on network connection especially windows 8.

Where to define <Environment...> elements in JBoss

I try to define environment entries in JBoss 5.1 and added following to the server/default/deploy/jbossweb.sar/context.xml file:
<Environment type="java.lang.String" name="name" value="value" />
Following error occurs on startup:
2010-01-26 14:50:08,383 ERROR
[org.jboss.web.tomcat.service.deployers.JBossContextConfig]
(main) XML error parsing: context.xml
org.jboss.xb.binding.JBossXBException:
Failed to parse source: Resource
cannot appear in this position.
Expected content of Context is
unordered_sequence: attributes?
InstanceListener* Realm? Parameters*
Manager? Loader? Valve* SessionCookie?
Resources? Listener*
Where may I define environment entries in JBoss (but outside of application's EAR)?
This article confirms that (likely) it is not possible to configure environment entries in JBoss. Author suggests to use PropertiesService as alternative.
Property configuration in properties-service.xml works great!