I have a problem with deploying the spring boot application after I delete the database and create new. When I deploy it I got an following exception:
29-Jan-2023 00:16:21.058 WARNING [main]
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc
The web application [ROOT] registered the JDBC driver
[com.mysql.cj.jdbc.Driver] but failed to unregister it when the web
application was stopped. To prevent a memory leak, the JDBC Driver has
been forcibly unregistered. 29-Jan-2023 00:16:21.059 WARNING [main]
org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads
The web application [ROOT] appears to have started a thread named
[mysql-cj-abandoned-connection-cleanup] but has failed to stop it.
This is very likely to create a memory leak. Stack trace of thread:
I read online, and I try the couple of methods and didn't work reference to the Stack Overflow answer: answer
When i move the MySQL driver to tomcat lib folder, I got another exception for class witch is not mark as entity:
javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: persistent class not known
Locally everything working fine. Any clues how to fix the issue, I don't have rights to restart the MySQL database at the moment and I search for fix.
From the answer I only create that class I am not sure if i need to call it somewhere.
Related
I'm getting weird behavior of Spring JDBC with Tomcat and Oracle db. During initializing of db connection (from pool which is configured in Tomcat) the driverClassName is empty, so I get ClassNotFoundException. I'm not sure why it is empty, the initialization during Tomcat startup looks OK. All ten connection have been initialized OK, but then a few hours later, the driverClassName is empty. Well, even the URL is empty.
I enabled debugging of 'org.apache.tomcat.jdbc.pool' to FINE to get more info, but no luck.
org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver Instantiating driver using class: [url=]
org.apache.tomcat.jdbc.pool.ClassLoaderUtil.loadClass Attempting to load class[] from java.net.URLClassLoader#10bbd20a
org.apache.tomcat.jdbc.pool.ClassLoaderUtil.loadClass Attempting to load class[] from ParallelWebappClassLoader
org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver Unable to instantiate JDBC driver.
java.lang.ClassNotFoundException: Unable to load class: from ClassLoader:java.net.URLClassLoader#10bbd20a;ClassLoader:ParallelWebappClassLoader
context: told-integration-tool
delegate: false
----------> Parent Classloader:
java.net.URLClassLoader#10bbd20a
I'm using:
Tomcat: 9.0.69
Spring JDBC: 5.3.22
ojdbc: 12.1.0.2.0
What do you think? Where could a problem?
I am doing a prototype for moving our Spring Boot based application to AWS Aurora DB including Serverless mode. With Provisioned mode things work as expected. However with serverless mode the application is not able to connect to the DB from EC2 instance with exception as:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'entityManagerFactory' defined in class path resource
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:
Invocation of init method failed; nested exception is javax.persistence.PersistenceException:
[PersistenceUnit: default] Unable to build Hibernate SessionFactory;
nested exception is org.hibernate.exception.JDBCConnectionException:
Unable to open JDBC Connection for DDL execution
.....
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException:
Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago.
The driver has not received any packets from the server.
I have tried reducing the initial pool size etc but still get the same error
spring.datasource.url=jdbc:mysql://xxxxxx.cluster-xxxxxxxxxx.us-east-1.rds.amazonaws.com:3306/db_example
spring.datasource.username=xxxx
spring.datasource.password=xxxxxxx
spring.datasource.hikari.maximum-pool-size=1
spring.datasource.hikari.minimum-idle=0
spring.datasource.hikari.connection-timeout=60000
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
....
When I change the Datasource to SimpleDataSource or run a simple java jdbc connection from EC2 instance it works.
#Bean("dataSource")
public DataSource dataSource() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
....
}
Is this normal with a Spring boot JPA/JDBC Application? Do we have to use a SimpleDriverDataSource? Perhaps are we rather supposed to use https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html? That will probably be re-writing a lot of DB related code.
In serverless mode, although highly optimized with a warn up pool of ready-to-go instances, your application requires some time until you can actually connect to Aurora.
For this reason, it is very likely that at the start of the application the connection to the database is not yet available.
It seems, for your error trace, that you are trying to do some kind of DDL operation, probably because you are using hbm2ddl to create or validate the database schema, and this operation requires a connection just while application is starting.
In order to support this kind of database architecture, you can lazily initialize your beans (which in the case of entity managers and Hibernate could be cornerstone), or look for an alternative approach for DDL generation like Liquibase (although I think the problem will remain).
You can try to tweak your Hikari connection parameters. For instance, this article propose a clever configuration and provides a great insight into AWS Aurora:
https://silexdata.com/modern-applications-and-aws-aurora-serverless/
The only thing that I do not understand is why your code works with SimpleDriverDataSource: maybe it provides some defaults that allow your app to connect to Aurora without error from the beginning.
My java web app has session checking. Every time I save, it redeploys. I've already checked the option in netbeans "Preserve Session Across Redeployment" but when i looked the logged. I have this error
Info: Initializing Mojarra 2.1.6 (SNAPSHOT 20111206) for context '/webapp'
Info: Running on PrimeFaces 3.4.2
Severe: PWC2768: IOException while loading persisted sessions: java.io.EOFException
java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2553)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1296)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946) ...
and further down the log
Warning: WEB0517: Unable to restore sessions for web module [/webapp] from previous deployment
java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2553)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1296)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
so every time I save java files, I need to login again.
How can I solve this. Thanks
I´m using hibernate 4.3.6 in my vaadin project.
Every time I make changes in the sources code, it is expected that the application builds again and the new source code is deployed automatically to Tomcat. In other words, Tomcat should reload its context.
The problem is that during this operation hibernate throws an error:
GRAVE: Exception loading sessions from persistent storage
org.hibernate.HibernateException: registry does not contain entity manager factory: myproject
at org.hibernate.jpa.internal.EntityManagerFactoryRegistry.getNamedEntityManagerFactory
(...)
After that log, i get:
24/09/2014 13:14:43 org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/myproject] is completed
However, I cannot continue using the website, since I receive a message saying that session is lost.
My question is: what is this hibernate exception and how can I solve it?
EDIT:
This error only happens when I store in session a JPA Entity, for example: the logged user
I don´t know any way to get what you want, in Tomcat, except with JRebel. The staff of Vaadin itself uses and recommends. Link with interesting information about Vaadin+JRebel: http://zeroturnaround.com/blog/jrebel-case-study-vaadin-eliminates-redeploys-and-saves-10-of-development-time/
If in the future you decide to use Jetty instead of Tomcat, you can make settings and get dynamic reloading of the application as suggested here: https://blog.oio.de/2012/08/23/dynamic-reloading-of-vaadin-applications-with-maven-and-eclipse /
I'm developing a JavaEE application on Glasfish Application Server. I'm developing so I'm continously deployig/undeploying the application.
Everything has worked great until few hours ago when I got this error while deploying :
GRAVE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
GRAVE: Exception while invoking class org.glassfish.javaee.full.deployment.EarDeployer prepare method
GRAVE: Exception while preparing the app
GRAVE: Could not resolve a persistence unit corresponding to the persistence-unit-ref-name [persistence/decreg-entite] in scope of the module called [declaration-reglementaire-ear#declaration-reglementaire-serviceweb-0.0.3-RELEASE.war]. Please verify your application.
org.glassfish.deployment.common.DeploymentException: Could not resolve a persistence unit corresponding to the persistence-unit-ref-name [persistence/decreg-entite] in scope of the module called [declaration-reglementaire-ear#declaration-reglementaire-serviceweb-0.0.3-RELEASE.war]. Please verify your application.
Has anyone an idea on how to solve this?
Thank you in andvace
it appears, the persistence unit named 'decreg-entite' is mentioned in your domain.xml file but the jpa configuration file, persistence.xml doesn't define all about the persistence unit.