What are the advantages of installing JDBC Driver as a Module in WildFly - jdbc

This link explains the new things about WildFly. Under the Migrating The Database Connection -> JDBC Driver the article explains about two ways of using jdbc drivers for the applications. I tried with installing it as a module and it works fine. The problem is which way is better and when it is better, whether deploy it as any other application package or install it as a module?
(I noted that install it as a module is necessary for clustered environment. I am looking for, are there any other reasons?)

I think the correct link to the article you are referencing is this one : http://wildfly.org/news/2014/02/06/GlassFish-to-WildFly-migration/
(The other one does not seem to point to the article you are mentioning)
Below is the interesting part from "Migrating The Database Connection" section you are referencing:
On WildFly, you have two ways of installing the JDBC driver: whether
you deploy it as any other application package or you install it as a
module. You can always choose to deploy the driver, but it’s specially
recommend when you have a cluster environment, since the deployments
are automatically propagated in the server groups.
You may have issues with the deployment if the driver is not
JDBC4-compliant. In this case, installing the driver as a module
solves those issues. The advantage of the JDBC driver as a module is
the possibility of creating a custom WildFly bundle for your
organization. This way, you can repeat exactly the same installation
throughout several machines, preserving the same configuration. This
is perfect for the development environment.
So in this section, the author describes the following advantage:
You may have issues with the deployment if the driver is not JDBC4-compliant. In this case, installing the driver as a module solves those issues.
The following Wildfly documentation describes this also:
Any JDBC 4-compliant driver will automatically be recognized and installed into the system by name and version. A JDBC JAR is identified using the Java service provider mechanism. Such JARs will contain a text a file named META-INF/services/java.sql.Driver, which contains the name of the class(es) of the Drivers which exist in that JAR. If your JDBC driver JAR is not JDBC 4-compliant, it can be made deployable in one of a few ways. (...)
Thus, deploying your driver as a module is easier than deploying it as any other application package in case it is not JDBC-4 compliant. (Because you would have to modify and rebuild your JDBC-4 not compliant jar to deploy it as any other application package)

Related

LinkageError on WebSphere 9 for javax.transaction.* classes

I have a web application that used to run fine on many web servers (tomcat, jboss, weblogic and websphere). Now, however, it has an error when deploying on WebSphere 9.
The app contains the jar javax.transaction-api-1.2. Some of its classes, e.g., javax.transaction.xa.XAResource, are also included in Java SE, but not all of them. Some are specific to Java EE and are required by some 3rd-party libraries in my app. The app is always deploying with child-first (parent-last) classloader.
WebSphere 9 throws this error during startup when the app tries to load the Oracle JDBC driver:
java.lang.LinkageError: loading constraint violation: loader "com/ibm/ws/classloader/CompoundClassLoader#7157be44" previously initiated loading for a different type with name
"javax/transaction/xa/XAResource" defined by loader "com/ibm/oti/vm/BootstrapClassLoader#422c7b1b"
Note that we aren't actually using XA transactions in the app, we are using regular transactions.
On other servers, and previous versions of WebSphere, it was never a problem. The server didn't care that we load XAResource from inside the war, even if it was previously loaded somewhere in the server. Now WebSphere 9 is different, it says that the app classloader already loaded this class from the server, but I don't know why or when did this happen.
Any idea how to solve this?
Remove the transaction API from your application. JTA 1.2 is already included in the server and provides no value in your applications. It's always risky to bring Java EE/SE APIs in a parent-last class loader unless you are 100% certain that they are technically necessary, because they can lead to issues like this one.
I can't say how this worked in previous server versions (there have been some Java-level changes in enforcing linkage issues like this), but the solution is reasonably straightforward.
At the end we did two things to solve this problem.
1) We upgraded the jta jar to version 1.3 (link here). This jar solves the problem by avoiding duplicate classes - it contains only J2EE classes and omits the J2SE classes that are already included in the JVM.
2) We upgraded WebSphere server from 9.0.0.7 to 9.0.0.11.
At the time, I suspected just upgrading the jar should suffice, but our QA had some issues with it and they also upgraded the server. Due to lack of time, we didn't investigate it further and just decided to do both.

Where is org.apache.derby.jdbc.ClientDriver for version 10.15.1.3?

I've downloaded the drivers via Maven Central (org.apache.derby).
derby-10.15.1.3.jar
derbyclient-10.15.1.3.jar
derbynet-10.15.1.3.jar
derbyshared-10.15.1.3.jar
So what am I missing ? None of these JARs contains the package "org.apache.derby.jdbc", which used to contain the ClientDriver and EmbeddedDriver in the past?
Indeed, to use the Derby client driver with Derby 10.15, you now need all three of: derbyclient.jar, derbyshared.jar, and derbytools.jar. This is (weakly) documented here:
A new jar file (derbyshared.jar) has been added. All Derby
configurations require it. In addition, the derbytools.jar library is
now required when running the network server and/or when using Derby
DataSources.
Since you are running the network server, you now require derbytools.jar (as well as the new derbyshared.jar when running the client software.
I think it would be worth suggesting to the Derby community that the release note could make this stand out more clearly (you could file an improvement request with the Derby project, e.g.)
It looks like derbytools depends on derbyshared, so you don't have to list derbyshared as a dependency in your pom.xml (just derbytools).
However, this seems to work counter to how every other jdbc client works for every other database. Rather than updating documentation to say you have to include extra dependencies, Derby should make the derbyclient stand alone (better solution) or have the maven derbyclient depend on derbytools (so that when this dependency problem is fixed, people won't have to go back and update their pom.xmls to remove unneeded dependencies).

Tibco Service JDBC SQL deployment issue

I have created a Service running on Tibco, containing a JDBC-enabled process within it, and tested it successfully. The database server is MySQL, and is hosted remotely. When connecting to the remote DB from the service hosted on my machine, the SQL is executed well, but after building the Tibco EAR file and deploying to another external machine, then trying to access the same remote DB server using the same credentials, the external machine returns the below error upon returning:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OPTION SQL_SELECT_LIMIT=DEFAULT' at line 1
So, a few questions:
What could be the cause of the above error, given the DB being accessed is the exact same one, using same SQL query, but from different machines?
Is the JDBC driver used for development compiled as part of the packaged EAR file?
Does the JDBC driver being used in a Tibco Process depend on the Tibco service installed or on the packaged EAR file?
Am asking from a learner PoV as am currently picking up Tibco
It looks like jdbc driver issue. You may have different mysql driver version in tibco designer and BusinessWorks.
You don't need to add jdbc driver to your ear package.
Please note that you can specify mysql driver in your package classpath. In tibco Administrator PackageName->Configuration->ServerSettings->Prepend to ClassPath or Append to Class path.
You can also try to copy the driver from your tibco designer(in BW5 it's in \tibco\bw\5.11\lib\
) to the BusinessWorks classpath

RazorSQL causes HSQLDB to throw org.hsqldb.HsqlException: Client driver version greater than '2.1.0.0' is required. HSQLDB server version is '2.3.4'

I am not able to connect to my HSQLDB database from RazorSQL. I am only having this issue when I am running in Server mode and when I am attempting to connect from RazorSQL.
Using the same URL from Eclipse Data Source Explorer, and from the application itself (which is a Hibernate 5.2.7 application), I am able to successfully connect to my database at the URL "jdbc:hsqldb:hsql://localhost/SudokuHibernate". Since I am running it in Server mode, I am able to connect concurrently.
(Note: I don't have to have multiple concurrent connections, but it make debugging easier). The database is being run in Server mode from the command line via ...
java -cp ../libs/hsqldb-2.3.4/hsqldb/lib/hsqldb.jar org.hsqldb.server.Server --database.0 file:/Users/arick/src/databases/SudokuHibernate --dbname.0 SudokuHibernate
When attempting to connect from RazorSQL, the database console shows the error message. "org.hsqldb.HsqlException: Client driver version greater than '2.1.0.0' is required. The HSQLDB server version is '2.3.4'".
Note: This is a different question then a similar StackOverflow question, as all of my own configuration files are explicitly referencing the same JDBC driver, from the same jar file. However, as pointed out by Fred T, the reference to '2.1.0.0', by HSQLDB, is somewhat misleading. It is really just saying that the client and the server have two different versions of the JDBC driver.
At the same time that the database is throwing a mismatched version error, RazorSQL displays a dialog box with the error message:
ERROR: An error occurred while trying to make a connection to the database:
JDBC URL: jdbc:hsqldb:hsql://localhost/SudokuHibernate
connection exception: connection failure: java.io.EOFException
Below is my RazorSQL connection profile.
RazorSQL Profile
Driver Location: /Users/arick/src/libs/hsqldb-2.3.4/hsqldb/lib/hsqldb.jar
JDBC URL: jdbc:hsqldb:hsql://localhost/SudokuHibernate
As was inferred by Mark Rotteveel, the answer is similar to a related question about how to get Eclipse and Maven to talk to a HSQLDB server that is running in standalone server mode.
In that case, Fred Toussi, the lead on the HSQLDB project, pointed out the answer was to modify the configuration file, that is used in Eclipse and Maven, to pull in the appropriate version of the HSQLDB JDBC jar file, and also to make sure the jar file didn't appear anywhere else on the classpath. Maven uses a pom.xml file for configuration; so what was needed was make sure that the correct version of the HSQLDB was defined in the project's pom.xml file.
In my situation, the RazorSQL product that I was using, just happens to use HSQLDB as the embedded database for itself. If I had been using any other Java database, I may not have had this problem. But, since the RazorSQL product had already loaded its own version of the HSQLDB jar file, it didn't matter what I specified in my configuration for the database connection. It wasn't going to work.
No matter how I changed my driver profile, or my connection profile, the only version of the HSQLDB jar file that was going to get loaded, was the original jar file, that was already in use by RazorSQL, and that came with RazorSQL. (Note: This is true, unless RazorSQL gets fancy, and it decides to use a different classloader, and some of the other tricks that are commonly used by Java applications servers to solve these problems).
As per suggestion from Dan Richardson, from RazorSQL, the actual answer was not by modifying my configurations, but by changing the contents of the RazorSQL distribution itself. I needed to replace the jar file that is used by the RazorSQL application. This jar file is in Mac application folder for RazorSQL. This location is typically at /Applications/RazorSQL.app/Contents/Java/drivers/hsqldb.
(Note: If you are not familiar with how to open a Mac app folder, you just right-click on the RazorSQL folder name in the /Applications directory and use the "Show Package Contents" menu option). In my case, I renamed the original hsqldb.jar file to be hsqldb_2.3.2.jar file, and then I copied in the last distribution of the hsqldb.jar.

java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

I am using aspectJ in my project and added dependencies in my POM file. When i am running my application on Websphere Application Server Liberty Profile, in the library folder aspectj.jar is not getting added/created. I am very new to using spring and never used server's to run a application. When i am trying to run the application on the server i am getting the following exception:
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
Can anyone please team whats going on wrong with the application ?
Thanks!
You'll need to make sure that aspectj is available to your application at runtime. The two basic approaches for this are to package it up with your application zip, or to make it available as a shared library in the server. The first approach has the advantage that you don't need to do any extra config, and no matter where you run your application, the dependency will be there. However, it has the disadvantage of bloating your application. If you end up running multiple applications on the server, it could also cause the apps to use more memory than they would if they were just using a shared copy.
For the first approach, if your dependency has the default scope in the pom, maven should automatically copy it to WEB-INF/lib (assuming your application is a war).
For the second approach, you can configure it in Liberty as a global library (available to all applications) by copying it to a wlp/usr/shared/config/lib/global folder in your Liberty install.

Resources