(Spring 4.3.3-Hibernate 5.1.5)Unable to create sessionFactory object - spring

Hi I am new to Hibernate and I am trying to integrate Spring 4.3.3 with Hibernate 5.1.5.
I am getting the following exception:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'loginController': Unsatisfied
dependency expressed through field 'loginservice'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'loginServiceImpl': Unsatisfied
dependency expressed through field 'loginDAO'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'loginDAOImpl': Unsatisfied dependency
expressed through field 'hibernateTemplate'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateTemplate' defined in ServletContext
resource [/WEB-INF/db-config.xml]: Cannot resolve reference to bean
'sessionFactory' while setting constructor argument; nested exception
is org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'sessionFactory' defined in ServletContext
resource [/WEB-INF/db-config.xml]: Invocation of init method failed;
nested exception is org.hibernate.MappingException: Could not get
constructor for
org.hibernate.persister.entity.SingleTableEntityPersister
My DB config file:
db-config.xml
Could someone please help me to solve this problem.

Related

Flyway integration(Enterprise Version) in Spring Boot problem

Hello i got this error when i use flyway enterprise in my springboot project:
16:27:46 WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.scheduling.annotation.ProxyAsyncConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'springAsyncConfig': Unsatisfied dependency expressed through field 'customAsyncExceptionHandler'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customAsyncExceptionHandler': Unsatisfied dependency expressed through field 'importHistoryRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'importHistoryRepository': Cannot create inner bean '(inner bean)#31db34da' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#31db34da': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration': Unexpected exception during bean creation; nested exception is java.lang.TypeNotPresentException: Type org.flywaydb.core.api.callback.FlywayCallback not present
Here is my pom.xml file:
<dependency>
<groupId>org.flywaydb.enterprise</groupId>
<artifactId>flyway-core</artifactId>
<version>6.0.3</version>
</dependency>
Related to this Issue Flyway 6.x.x is not compatible with Spring Boot < 2.2.0.
So you got 2 Choices:
Update Spring Boot to >= 2.2.0
Use flyway 5.x.x
Hope this helps

Cassandra-3.7 connection from Spring boot 2.1.2/2.1.6

We have an application developed in spring boot and we do use cassandra.
Our application was suing spring boot 1.4, cassandra 3.7 and JDK 1.8
Now we are tryign to upgrade spring boot to 2.1.2/2.1.6 and JDK 1.8 to Open JDK 11.0.2 and cassandra is as : 3.7
So when we are trying, we are recieving the
Caused by: com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed.
(com.datastax.driver.core.exceptions.TransportException: [HOSTS] Error writing)
Not sure what is going wrong.
Couple of pointers is:
1) Application is running fine on local on eclipse and this is issue when we are trying to start the application in server
Here is the stacktrace I see:
WARN 10473 --- [ main] org.eclipse.jetty.webapp.WebAppContext : Failed startup of context o.s.b.w.e.j.JettyEmbeddedWebAppContext#75a118e6{application,/console,[org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory$LoaderHidingResource#1d540566],UNAVAILABLE}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 1;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthIndicatorAutoConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicatorRegistry]: Factory method 'healthIndicatorRegistry' threw exception;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthIndicatorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraTemplate' defined in class path resource [CassandraDatabaseConfig.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.core.CassandraAdminTemplate]: Factory method 'cassandraTemplate' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [CassandraDatabaseConfig.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.cassandra.SessionFactory]: Factory method 'sessionFactory' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'session' defined in class path resource [CassandraDatabaseConfig.class]: Invocation of init method failed;
nested exception is com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: host1:port1 (com.datastax.driver.core.exceptions.TransportException: [host1:port1] Error writing))
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
Please let me know if any more additional details needed.
Tried to changed version of Cassandra driver version, explicilty trying to logging to Cassandra
This is our CassandraConfig class where we create the cluster object.
CassandraClusterFactoryBean cluster = new CassandraClusterFactoryBean();
cluster.setContactPoints(contactPoints);
cluster.setPort(Integer.valueOf(port));
cluster.setUsername(userName);
cluster.setPassword(password);
return cluster;
Server should start by connecting to cassandra

Unable to use MicroMeter instead Of Prometheus

I upgraded my Spring Version from 1.5 to 2.0 and upgraded Prometheus version 0.3.0 to 0.6.0. But unfortunately, it was not working. I was told I have to use MicroMeter instead of SimpleClient and added io.micrometer to my pom.xml and #EnablePrometheusEndpointremoved for my MetricConfig class but I come across with following error. Do you know why I get such kind of error ?
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'servletEndpointRegistrar' defined in
class path resource
[org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate
[org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]:
Factory method 'servletEndpointRegistrar' threw exception; nested
exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'routeControllerEndpoint' defined in
class path resource
[org/apache/camel/spring/boot/actuate/endpoint/CamelRouteControllerEndpointAutoConfiguration.class]:
Unsatisfied dependency expressed through method
'routeControllerEndpoint' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'camelContext' defined in class path resource
[org/apache/camel/spring/boot/CamelAutoConfiguration.class]:
Post-processing of merged bean definition failed; nested exception is
java.lang.IllegalStateException: Failed to introspect Class
[org.apache.camel.impl.DefaultCamelContext] from ClassLoader
[jdk.internal.loader.ClassLoaders$AppClassLoader#77556fd]

org.springframework.beans.factory.UnsatisfiedDependencyException:oracle driver not found

I am using SPRING BOOT ORACLE JPA with GRADLE a simple project but while running I am getting:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name
'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration':
Unsatisfied dependency expressed through constructor parameter 0;
nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource' defined in class path resource
[org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method
'dataSource' threw exception; nested exception is
java.lang.IllegalStateException: Cannot load driver class:
oracle.jdbc.driver.OracleDriver
My application.properties are:
server.port=8082 # create n drop tables, loads import.sql
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:oracle:thin:#//138.69.14.63:1521/drbadev
spring.datasource.username=$$$$$$$$$$ spring.datasource.password=$$$$$$
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
What can I do to solve this?

SPRING Lookup failed for 'jdbc/ww2b/DataSource' in SerialContext

[#|2014-04-01T15:19:03.824+0200|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=76;_ThreadName=Thread-2;|15:19:03.822 [admin-thread-pool-4848(5)] ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'categoryUiDao': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [jar:file:/C:/glassfish3/glassfish/domains/domain1/applications/web/WEB-INF/lib/core-2.6-SNAPSHOT.jar!/META-INF/spring/db-env.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in URL [jar:file:/C:/glassfish3/glassfish/domains/domain1/applications/web/WEB-INF/lib/core-2.6-SNAPSHOT.jar!/META-INF/spring/db-env.xml]: Invocation of init method failed; nested exception is javax.naming.NamingException: Lookup failed for 'java:comp/env/jdbc/ww2b/DataSource' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Lookup failed for 'jdbc/ww2b/DataSource' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming, com.sun.enterprise.naming.logicalName=java:comp/env/jdbc/ww2b/DataSource} [Root exception is javax.naming.NameNotFoundException: ww2b]]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) ~[spring-beans-3.0.5.RELEASE.jar:3.0.5.RELEASE]
what is wrong. When I build a project everything works but when I try to deploy to glassfish3 I get error.
Assuming your Spring application configuration is right it seems that the JNDI resource java:comp/env/jdbc/ww2b/DataSource is not correctly configured on the server.
You should configure JNDI resource on GlassFish as described in the Administrator Guide.

Resources