Spring with HSQLDB latest 2.4.0 version not working - java

I am trying to create simple Java 1.7 project for Spring with HSQL DB.
I downloaded latest version of HSQL DB and created a simple file based DB.
In java project I am using latest version of Spring, HSQL and related jar. But while running program I am getting error
Exception in thread "main" java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=org/hsqldb/jdbcDriver, offset=6
My file is
<!-- Spring framework -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.2.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hsqldb/hsqldb -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.4.0</version>
What should be change in jars ?

HSQLDB 2.4.0 has been compiled with JDK 8 and cannot be used with JDK 7 or earlier.
You need to specify version 2.3.5 for a version that has been compiled with JDK 6. This version lacks the new JDBC features introduced in Java 8 but is compatible with version 2.4.0 in other respects.

Related

jax-rs #.Provider is not being called

I have a RESTfull JAX-RS , which uses a custom #Provider for exception handling, which looks as follows:
#Provider
public class ValidationExceptionHandler implements ExceptionMapper<MethodConstraintViolationException> {
#Override
public Response toResponse(MethodConstraintViolationException exception) {
// some code here
return Response.status(Status.OK).entity(claimWithPaymentResponse).build();
}
}
This provider used to work OK, when my application run under JBoss 6 EAP and Java 7. However, since upgrading to JBoss 7 EAP with JDK 11 and updating the required dependencies in my pom.xml, this Provider is not called at all.
This is an excerpt from my pom.xml with the relvant frameworks:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>2.3.6.Final</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-hibernatevalidator-provider</artifactId>
<version>2.3.6.Final</version>
</dependency>
<dependency> <!-- vpc9528, 2022-07-14, P1681-311 fixed "Provider com.sun.xml.internal.ws.spi.ProviderImpl not found", #see https://stackoverflow.com/questions/54032558/jdk-11-jax-ws-provider-com-sun-xml-internal-ws-spi-providerimpl-not-found -->
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.jws</groupId>
<artifactId>javax.jws-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
Your javax.ws.rs-api dependency is not marked as provided. That means that it gets bundled into your application. The #Provider annotation on your class is the bundled one, but it's not the one JBoss is looking for - that's the one provided by JBoss.
Any APIs from Java/Jakarta EE should be marked as provided when you're working with JBoss, WildFly, GlassFish, or other JEE containers. In your case that's not just javax.ws.rs-api but also jaxb-api. I think that the same holds for resteasy-hibernatevalidator-provider. I expected the same for rt but apparently you're getting errors without it.

After upgraded Hibernate-Jakarta version, application doesn't work

I upgraded hibernate-core-jakarta version. I get this error when trying to run the project.
The project includes; Java17, spring boot 2.7.x
java.lang.NoClassDefFoundError: org/springframework/aot/hint/TypeHint$Builder
error logs
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core-jakarta</artifactId>
<version>5.6.14.Final</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>jakarta.mail</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>6.0.3</version>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.0.0</version>
</dependency>
With Spring Boot 2.7, you should use the normal hibernate-core dependency, not hibernate-core-jakarta. You should also let Spring Boot manage the versions of your dependencies, not specify them yourself.
You seem to have added multiple dependencies using the jakarta.* package namespace, which do not work with Spring Boot 2.7, you would need to upgrade to Spring Boot 3.0 if you want to use Jakarta EE 9 libraries (and again, then you should still let Spring Boot manage your versions instead of specifying them yourself).
The same goes for Spring. Spring Boot 2.7 uses Spring 5.3, it cannot use Spring 6. This is likely the immediate cause of the "java.lang.NoClassDefFoundError: org/springframework/aot/hint/TypeHint$Builder".
TL;DR, stop managing your versions like this, and let Spring Boot manage them for you.
If you want to use Jakarta EE 9+ (using the jakarta.* package namespace) and Spring 6 dependencies, you have to upgrade to Spring Boot 3, not upgrade individual dependencies yourself.

HikariCP upgrade to Debian 10 (mariadb)

I had database connection issues on my Java project because of mysql's replacement with mariadb on Debian 10. I am using HikariCP to connect, I updated the code so that it works with mariadb :
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setMaximumPoolSize(10);
hikariConfig.setDriverClassName("org.mariadb.jdbc.Driver"); // added after internet research about hikaricp and mariadb
hikariConfig.setJdbcUrl("jdbc:mariadb://localhost:3306/" + db);
hikariConfig.setUsername(user);
hikariConfig.setPassword(pass);
I upgraded my HikariCP setup : I replaced 2.7.8 with 3.4.5 (even though I don't know what's the difference) and added the mysql-connector dependency after viewing this post (btw there is no version for this guy's mysql-connector in his pom.xml but I had to put one so I chosed 6.0.6) and I am still getting a Java error :
java.lang.RuntimeException: Failed to load driver class org.mariadb.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:486)
pom.xml dependencies
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.12-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>3.4.5</version>
</dependency>
</dependencies>
Thank you for reading me, I hope someone has a solution
You are using mariadb now, not mysql. Change
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>6.0.6</version>
</dependency>
to
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
<version>2.7.3</version>
</dependency>

Conflicts in xwork and xwork-core

I have been trying to integrate Struts 2 with Zero Configuration, Spring, Hibernate and Maven.
But, what I think there must be something which I am missing in integration and it must be related to the configuration of Maven's Pom.xml:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.1.8.1</version>
</dependency>
<!-- Struts 2 + Spring plugins -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.1.8.1</version>
</dependency>
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!-- Spring framework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.5.6</version>
</dependency>
<!-- Hibernate core -->
<dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.3</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.7.Final</version>
</dependency>
<!-- Hibernate core library dependency start -->
<!-- Hibernate core library dependency end -->
<!-- Hibernate query library dependency start -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.1.8.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
</dependency>
As when I use this configuration it gives me an error
java.lang.NoSuchMethodError: com.opensymphony.xwork2.util.finder.UrlSet.<init>(Lcom/opensymphony/xwork2/util/finder/ClassLoaderInterface;Ljava/util/Set;)V
And instead of opensymphony XWork libaray I use dependency of
<dependency>
<groupId>org.apache.struts.xwork</groupId>
<artifactId>xwork-core</artifactId>
<version>2.3.8</version>
</dependency>
It throws me this exception
Caused by: Unable to load configuration. - [unknown location]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
When you upgrade the version of Struts2, you have to update the libraries requires by your application to the target version. Each distro of Struts2 supplied with the corresponding set of libraries in the lib folder that are compatible with the version of distro. If you use maven to resolve and fetch the dependencies you should consider the artifact struts2-core.
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.8</version>
</dependency>
It will fetch all required dependencies for this artifact, other dependencies, such as plugins you need to add separately. Use the same version targeted to plugins. For example to add a convention plugin use
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.8</version>
</dependency>
The targeted version number I've chosen 2.3.8 but it's possibly incompatible with the other features i.e. Hibernate and Spring which versions need to upgrade separately by adding corresponding artifacts to the dependencies.
And finally and most time consuming is changes to the source code of the project, update the configuration files according to newer DTDs , API changes, fix deprecations. For this purpose consider reading the release notes.
Also see the example of developing a Maven project: Create Struts 2 Web Application Using Maven To Manage Artifacts and To Build The Application.

What maven artifacts do I need for spring hibernate and mysql support?

I have a IDEA project using maven2.
I want to use hibernate + mysql, what dependancies do I need?
first of all, I separate the versions from the artifacts:
<properties>
<spring.version>3.0.3.RELEASE</spring.version>
<hibernate.version>3.5.3-Final</hibernate.version>
<mysql.version>5.1.13</mysql.version>
<junit.version>4.7</junit.version>
</properties>
then I reference them like this:
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<!-- perhaps using scope = provided, as this will often
be present on the app server -->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<!-- or hibernate-entitymanager if you use jpa -->
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
That way you keep the versions all in one place and can easily update them, especially if you reference e.g. multiple spring artifacts.
BTW: these should be the current versions, but you can always look up current versions using MvnRepository.com
Pasting these dependencies into pom.xml after <depdendencies> should work:
<!-- MySQL database driver -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!-- Hibernate framework -->
<dependency>
<groupId>hibernate</groupId>
<artifactId>hibernate3</artifactId>
<version>3.2.3.GA</version>
</dependency>
<!-- Hibernate library dependecy start -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<!-- Hibernate library dependecy end -->
Shamelessly cloned from http://www.mkyong.com/hibernate/quick-start-maven-hibernate-mysql-example/ (with the addition of jta as recommended by a commenter)
You may want to tweak the version numbers on the dependencies.
IntelliJ IDEA 9 can find Maven dependencies based on class name. If you start using a class which isn't available in the current dependencies you can get IntelliJ to help find it by using Alt-Enter.
I used this to great effect with a Java-base Subversion hook implementation I am building at work. I was able to get SVNKit and Google Guice dependencies into my project fairly easily this way.
MySQL in your case may be trickier since it is more of a runtime dependency when using Hibernate.

Categories