spring mvc 3 with hibernate (and hibernate.hbm2ddl.auto) - java

I've a problem setting up spring mvc 3 and hibernate with the auto dll
this is my folder structure:
And these are my libraries:
AbstractUser
package org.andreadorigo.abstracts;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
/**
* Generic user
* #author andreadorigo
*
*/
public abstract class AbstractUser {
#Id
#Column(name="id")
#GeneratedValue
private Integer id;
#NotEmpty
#Email
#Column(name="email")
public String email;
#NotEmpty
#Size(min = 6, max = 14)
#Column(name="password")
public String password;
/**
*
*/
public AbstractUser() {
super();
}
//Getters and setters
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
CustomerUser
package org.andreadorigo.entities;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.andreadorigo.abstracts.AbstractUser;
#Entity
#Table(name="customerUser")
public class CustomerUser extends AbstractUser{
}
dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.andreadorigo" />
<mvc:annotation-driven />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
id="entityManagerFactory">
<property
name="persistenceUnitName"
value="jtdb" />
<property
name="dataSource"
ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property
name="showSql"
value="true" />
<property
name="generateDdl"
value="true" />
<property
name="databasePlatform"
value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
</beans>
hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="transaction.factory_class">org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory</property>
<property name="hibernate.hbm2ddl.auto">create</property>
</session-factory>
</hibernate-configuration>
persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="CustomerUser">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>org.andreadorigo.entities.CustomerUser</class>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
</persistence-unit>
</persistence>
But when I run jboss 7 I get these warnings/errors:
15:48:57,442 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:48:58,322 INFO [org.hibernate.validator.util.Version] (MSC service thread 1-2) Hibernate Validator 4.2.0.Final
15:48:59,172 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:48:59,614 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-2) Monitoring jndi:/default-host/GenericProject/WEB-INF/faces-config.xml for modifications
15:49:00,295 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:00,405 INFO [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /GenericProject
15:49:01,010 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:01,271 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:01,529 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:01,778 INFO [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-3) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
15:49:01,795 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:02,061 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:02,310 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#55e3c942: defining beans [registerController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,viewResolver,entityManagerFactory]; root of factory hierarchy
15:49:02,374 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:02,749 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:03,126 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:03,505 WARN [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:03,839 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#55e3c942: defining beans [registerController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,viewResolver,entityManagerFactory]; root of factory hierarchy
15:49:03,875 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroy method on bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#0' threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization
15:49:04,031 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroy method on bean with name '(inner bean)' threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization
15:49:04,182 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroy method on bean with name 'org.springframework.format.support.FormattingConversionServiceFactoryBean#0' threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization
15:49:04,381 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroy method on bean with name 'registerController' threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization
15:49:04,530 ERROR [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-3) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]
15:49:04,868 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringTest]] (MSC service thread 1-3) StandardWrapper.Throwable: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]
15:49:05,194 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringTest]] (MSC service thread 1-3) Servlet /SpringTest threw load() exception: java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]

There are at least 2 things wrong here
You are mixing spring versions 3.0.3 and 3.1.1, never mix different spring versions (well actually that goes for all frameworks).
You are at least missing the spring-tx.jar and spring-aop.jar.
I strongly suggest using Maven or Gradle for managing your dependencies, saves you a lot of headaches searching for jars around the internet.
Next to that make up your mind on what you want to use for configuration, you have your entitymanager configured through a hibernate.cfg.xml, spring context file and persistence.xml. Why? Remove at least the hibernate.cfg.xml and put the needed config in persistence.xml.

You seem to be missing the spring-tx jar from your classpath given this line
15:49:04,031 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory]
(MSC service thread 1-3) Destroy method on bean with name '(inner bean)'
threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization
You can get it here.
You actually seem to be missing much more than that.
java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
Get all the spring jars from the here.

Related

How to configure Jakarta persistence on wildfly 21

Thank you and sorry in advance!
I am working on upgrading our wildfly version from 8 to 21.
Back in the days of 8, wildfly shipped with hibernate for the default persistence engine, it appears that now it ships with Jakarta. So, I am going through the process of attempting to get the persistence working and am running into the below-listed errors.
I have a clean download of wildly 21.0.2.Final, I have modified the standalone.xml to include my data sources which I believe are being loaded correctly because these lines that end up in the log.
10:48:46,578 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) WFLYJCA0001: Bound data source [java:jboss/datasources/unitTestDS]
10:48:46,578 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) WFLYJCA0001: Bound data source [java:jboss/datasources/localLiveDS]
persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="ertDatasource">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/localLiveDS</jta-data-source>
<properties>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.enable_lazy_load_no_trans" value="true"/>
</properties>
</persistence-unit>
</persistence>
test-persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="ertDatasource">
<jta-data-source>java:jboss/datasources/unitTestDS</jta-data-source>
<properties>
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
<property name="hibernate.enable_lazy_load_no_trans" value="true"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
</properties>
</persistence-unit>
</persistence>
Here are the errors and warnings that I get when running the ./stabdalone.sh command
10:48:41,634 WARN [org.jboss.as.domain.management.security] (MSC service thread 1-4) WFLYDM0111: Keystore /Applications/Wildfly/wildfly-21.0.2.Final-Clean/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
10:48:46,749 WARN [org.jboss.modules.define] (MSC service thread 1-5) Failed to define class org.hibernate.ejb.HibernatePersistence in Module "deployment.<project name>-api.war" from Service Module Loader: java.lang.IncompatibleClassChangeError: Failed to link org/hibernate/ejb/HibernatePersistence (Module "deployment.<project name>-api.war" from Service Module Loader): class org.hibernate.ejb.HibernatePersistence has interface org.hibernate.ejb.AvailableSettings as super class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:839)
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:424)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:555)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:339)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:126)
at org.jboss.modules.Module.loadModuleClass(Module.java:731)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:247)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at org.jboss.as.jpa.processor.PersistenceProviderHandler.deploy(PersistenceProviderHandler.java:73)
at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:49)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.lang.Thread.run(Thread.java:748)
10:48:46,751 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.unit."<project name>-api.war".FIRST_MODULE_USE: org.jboss.msc.service.StartException in service jboss.deployment.unit."<project name>-api.war".FIRST_MODULE_USE: WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment "<project name>-api.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:189)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IncompatibleClassChangeError: Failed to link org/hibernate/ejb/HibernatePersistence (Module "deployment.<project name>-api.war" from Service Module Loader): class org.hibernate.ejb.HibernatePersistence has interface org.hibernate.ejb.AvailableSettings as super class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.lang.ClassLoader.defineClass(ClassLoader.java:839)
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:424)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:555)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:339)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:126)
at org.jboss.modules.Module.loadModuleClass(Module.java:731)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:247)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at org.jboss.as.jpa.processor.PersistenceProviderHandler.deploy(PersistenceProviderHandler.java:73)
at org.jboss.as.jpa.processor.PersistenceBeginInstallProcessor.deploy(PersistenceBeginInstallProcessor.java:49)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
... 8 more
10:48:46,815 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "<project name>-api.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"<project name>-api.war\".FIRST_MODULE_USE" => "WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment \"<project name>-api.war\"
Caused by: java.lang.IncompatibleClassChangeError: Failed to link org/hibernate/ejb/HibernatePersistence (Module \"deployment.<project name>-api.war\" from Service Module Loader): class org.hibernate.ejb.HibernatePersistence has interface org.hibernate.ejb.AvailableSettings as super class"}}
10:48:46,861 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 21.0.2.Final (WildFly Core 13.0.3.Final) started (with errors) in 22664ms - Started 336 of 599 services (1 services failed or missing dependencies, 373 services are lazy, passive or on-demand)
In the wildfly-root/modules/system/layers/base/javax/persistence/api/main folder I have the module.xml and the jakarta.persistence-api-2.2.3.jar
module.xml content
<?xml version="1.0" encoding="UTF-8"?>
<module name="javax.persistence.api" xmlns="urn:jboss:module:1.7">
<dependencies>
<!-- PersistenceUnitInfo needs javax.sql.DataSource -->
<module name="javax.api" export="true"/>
</dependencies>
<resources>
<resource-root path="jakarta.persistence-api-2.2.3.jar"/>
</resources>
</module>
I have added the Jakarta persistence dependency
<!-- https://mvnrepository.com/artifact/jakarta.persistence/jakarta.persistence-api -->
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.3</version>
</dependency>
I also have this, not sure if I need it though.
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.4.Final</version>
</dependency>
Wondering what dumb thing I am missing?
EDIT:
I have added this to the dependencyManagement section:
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-jakartaee8-with-tools</artifactId>
<scope>import</scope>
<type>pom</type>
<version>21.0.2.Final</version>
</dependency>
And I now get this new error:
14:20:07,862 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 82) MSC000001: Failed to start service jboss.persistenceunit."eventhub-api.war#ertDatasource": org.jboss.msc.service.StartException in service jboss.persistenceunit."eventhub-api.war#ertDatasource": java.lang.AbstractMethodError
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:198)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:128)
at java.security.AccessController.doPrivileged(Native Method)
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:659)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:213)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:513)
Caused by: java.lang.AbstractMethodError
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:276)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:467)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1250)
at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:170)
... 10 more
14:20:07,865 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"eventhub-api.war#ertDatasource\"" => "java.lang.AbstractMethodError
Caused by: java.lang.AbstractMethodError"}}
WildFLy is throwing exception when deployment your application. Also You shouldn't link which is an API that is provided by WildFly except if you remove JPA support from WildFly. Also WildFly is compatible with jakartaEE 8 so you shouldn't link your deployment to some API provided by WildFLy.
For JakartaEE 9 you should use WildFly preview

Error while starting Wildfly 11 App Server - persistence unit named null

I'm developing a maven based JSF+JPA+EJB 3.2 Project using Eclipse and Wildfly 11.
While starting the App Server am getting the following error :
20:37:27,664 INFO [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0003: Processing weld deployment erpmini.war
20:37:28,116 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-4) HV000001: Hibernate Validator 5.3.5.Final
20:37:28,552 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-4) WFLYEJB0473: JNDI bindings for session bean named 'UserManagementServiceSlsb' in deployment unit 'deployment "erpmini.war"' are as follows:
java:global/erpmini/UserManagementServiceSlsb!com.itsys.erp.server.commonservices.usermgmt.UserManagementService
java:app/erpmini/UserManagementServiceSlsb!com.itsys.erp.server.commonservices.usermgmt.UserManagementService
java:module/UserManagementServiceSlsb!com.itsys.erp.server.commonservices.usermgmt.UserManagementService
java:jboss/exported/erpmini/UserManagementServiceSlsb!com.itsys.erp.server.commonservices.usermgmt.UserManagementService
java:global/erpmini/UserManagementServiceSlsb
java:app/erpmini/UserManagementServiceSlsb
java:module/UserManagementServiceSlsb
20:37:29,879 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."erpmini.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."erpmini.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "erpmini.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:172)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0041: Component class com.itsys.erp.server.commonservices.usermgmt.slsbadapter.UserManagementServiceSlsb for component UserManagementServiceSlsb has errors:
WFLYJPA0033: Can't find a persistence unit named null in deployment "erpmini.war"
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor$1.handle(ModuleJndiBindingProcessor.java:157)
at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.processClassConfigurations(ModuleJndiBindingProcessor.java:186)
at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:143)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:165)
... 5 more
20:37:30,098 INFO [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-2) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.8.Final
20:37:31,825 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 63) WFLYCLINF0002: Started client-mappings cache from ejb container
20:37:32,131 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "erpmini.war")]) - failure description: {
"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"erpmini.war\".INSTALL" => "WFLYSRV0153: Failed to process phase INSTALL of deployment \"erpmini.war\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0041: Component class com.itsys.erp.server.commonservices.usermgmt.slsbadapter.UserManagementServiceSlsb for component UserManagementServiceSlsb has errors:
WFLYJPA0033: Can't find a persistence unit named null in deployment \"erpmini.war\""},
"WFLYCTL0412: Required services that are not installed:" => ["jboss.deployment.unit.\"erpmini.war\".beanmanager"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.deployment.unit.\"erpmini.war\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"erpmini.war\".beanmanager]",
"jboss.deployment.unit.\"erpmini.war\".batch.artifact.factory is missing [jboss.deployment.unit.\"erpmini.war\".beanmanager]"
]
}
I'm injecting the EntityManager in stateless bean:
#Stateless
public class UserManagementServiceSlsb implements UserManagementService {
/** The Entity Manager */
#PersistenceContext(name = "TELCOAppPU")
private EntityManager entityManager;
private UserManagementService userMgmtService;
....
}
Why the Container is not able to find persistence.xml file? persistence.xml is present in META-INF directory. Any help would be appreciated.
Thanks.
UPDATE :
here is Project dir structure , persistence.xml is present in META-INF directory.
Project dir structure
persistence.xml contains Entity classes and MySql database connection details.
<persistence-unit name="TELCOAppPU">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.itsys.erp.server.dal.entities.City</class>
<class>com.itsys.erp.server.dal.entities.Machine</class>
<class>com.itsys.erp.server.dal.entities.Product</class>
<class>com.itsys.erp.server.dal.entities.ProductType</class>
<class>com.itsys.erp.server.dal.entities.ProductionLog</class>
...
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/erpdb" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
Solved it by adding resources folder (as source folder) to the path src/main/resources and moving the META-INF folder to resources folder, which in turn tells maven to put all files under resources directory to target/classes and in WEB-INF/classes in the WAR.
Try placing your persistance.xml file inside WEB-INF (src/main/webapp/WEB-INF) directory, Since in case of a war, that is where you are supposed to place your persisntence.xml file.

Error inserting second datasource with GenericDAO

Error inserting second datasource with GenericDAO
I'm trying to insert a second base in persistence.xml. I have already configured the datasource in jboss and tested it. When inserting a second persistence-unit in xml and attempting to raise jboss the error below occurs. I tried to set in each DAO class #PersistenceContext(unitName = "unit-name") and #PersistenceUnit, but to no avail. I tried to follow some tutorials, but I did not understand how to fit step by step in my context, nor do I know if this is the case.
I want to know how to configure for my case, I think the biggest difference is that I have an EntityManager coming from a GenericDAO and this is making it difficult for me to understand. If I have to annotate something else in DAOs or entities, what if I have to create another abstract class?
Erro:
The persistent unitName has not been specified and there are
persistent drive definitions 2 in the deployment of the deployment
application "intranet.war". You can either change the deployment of
the application to only have one definition of the persistence unit or
specify the unitName for each reference of a persistence unit.
17: 37: 11,411 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080
17: 37: 11,491 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Data source limit [java: jboss / datasources / ExampleDS]
17: 37: 11,492 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) WFLYJCA0001: Data source limit [java: jboss / datasources / intraDS]
17: 37: 11,491 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0001: Data source limit [java: jboss / datasources / intrasis]
17: 37: 11,524 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-4) WFLYDS0013: The FileSystemDeploymentService has been started for the directory C: \ Users \ vinicius.cipolli \ Devlopment \ jboss-eap -7.0 \ standalone \ deployments
17: 37: 11,528 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0027: c "intranet.war" (runtime-name: "intranet.war")
17: 37: 11,621 INFO [org.infinfin.factories.GlobalComponentRegistry] (MSC service thread 1-8) ISPN000128: Infinispan version: Infinispan 'Mahou' 8.1.2.Final-redhat-1
JBWS022052: Starting JBossWS 5.1.3.SP1-redhat-1 (Apache CXF 3.1.4.redhat-1) 17:37:11,661 INFO [org.jboss.ws.common.management] (MSC service thread 1-6)
17: 37: 12,706 INFO [org.jboss.as.jpa] (MSC service thread 1-5) WFLYJPA0002: Read the persistence.xml for intranet
17: 37: 12,707 INFO [org.jboss.as.jpa] (MSC service thread 1-5) WFLYJPA0002: Read the persistence.xml for intrasis
17: 37: 12,708 WARN [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0065: Invalid signature for method init annotated with javax.annotation.PostConstruct in br.sp.corpedu.intranet.domain .acod.service.EspecialityService class. The signature must be 'void methodName (InvocationContext ctx)'
17: 37: 12,709 WARN [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0065: Invalid signature for method init annotated with javax.annotation.PostConstruct in br.sp.corpedu.intranet.expose .resources.CourseResource class. The signature must be 'void methodName (InvocationContext ctx)'
17: 37: 12,709 WARN [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0065: Invalid signature for method init annotated with javax.annotation.PostConstruct in br.sp.corpedu.intranet.expose .resources.ResourceSpeciality of the class. The signature must be 'void methodName (InvocationContext ctx)'
17: 37: 12,709 WARN [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0065: Invalid signature for method init annotated with javax.annotation.PostConstruct in br.sp.corpedu.intranet.expose .resources.esto.ItemResource of the class. The signature must be 'void methodName (InvocationContext ctx)'
17: 37: 12,719 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit. "Intranet.war" .DEPENDENCIES: org.jboss.msc .service.StartException in service jboss.deployment.unit. "intranet.war" .DEPENDENCIES: WFLYSRV0153: Failed to process DEPENDENCIES phase of deployment "intranet.war"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start (DeploymentUnitPhaseService.java:154)
    at org.jboss.msc.service.ServiceControllerImpl $ StartTask.startService (ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl $ StartTask.run (ServiceControllerImpl.java:1881)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:624)
    at java.lang.Thread.run (Thread.java:748)
Caused by: java.lang.IllegalArgumentException: WFLYJPA0061: The persistent unitName has not been specified and there are persistent drive definitions 2 in the deployment of the deployment application "intranet.war". You can either change the deployment of the application to only have one definition of the persistence unit or specify the unitName for each reference of the persistence unit.
    at org.jboss.as.jpa.container.PersistenceUnitSearch.ambiguousPUError (PersistenceUnitSearch.java:187)
    at org.jboss.as.jpa.container.PersistenceUnitSearch.findWithinDeployment (PersistenceUnitSearch.java:153)
    at org.jboss.as.jpa.container.PersistenceUnitSearch.findPersistenceUnitSupplier (PersistenceUnitSearch.java:75)
    at org.jboss.as.jpa.container.PersistenceUnitSearch.resolvePersistenceUnitSupplier (PersistenceUnitSearch.java:64)
    at org.jboss.as.jpa.processor.JPAAnnotationProcessor.getPersistenceUnit (JPAAnnotationProcessor.java:372)
    at org.jboss.as.jpa.processor.JPAAnnotationProcessor.getBindingSource (JPAAnnotationProcessor.java:296)
    at org.jboss.as.jpa.processor.JPAAnnotationProcessor.processField (JPAAnnotationProcessor.java:171)
    at org.jboss.as.jpa.processor.JPAAnnotationProcessor.processPersistenceAnnotations (JPAAnnotationProcessor.java:138)
    at org.jboss.as.jpa.processor.JPAAnnotationProcessor.deploy (JPAAnnotationProcessor.java:100)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start (DeploymentUnitPhaseService.java:147)
        ... more
    
 
    17:37:12:17 ERROR [org.jboss.as.controller.management-operation]
     (Controller Boot Thread) WFLYCTL0013: Deploy Failure -
     address ([("deployment" = "intranet.war"])) - failure to describe:
     {"WFLYCTL0080: Service Failure" =
     {"jboss.deployment.unit. \" intranet.war \ "DEPENDENCIES" =
     "org.jboss.msc.service.StartException in service
     jboss.deployment.unit. \ "intranet.war \" DEPENDENCIES: WFLYSRV0153:
     Failed to process DEPENDENCIES phase of deployment \ "intranet.war \"
         Caused by: java.lang.IllegalArgumentException: WFLYJPA0061: The persisted unitName has not been specified and there are
    Persistent Drive 2 in Deployment Deployment
    \ "intranet.war \". You can either change the application deployment
    to have only one
    specify the unit for each reference of a unit of
    persistence. "}} 17: 37: 12,752 INFO [org.jboss.as.server]` enter code here`
    (ServerService Thread Pool - 34) WFLYSRV0010: Deployed
    "intranet.war" (runtime-name: "intranet.war")
The persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="intranet" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/intraDS</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
<persistence-unit name="intrasis" transaction-type="JTA">
<jta-data-source>java:jboss/datasources/intrasis</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
</properties>
</persistence-unit>
</persistence>
The GenericDAO class
public abstract class GenericDAO<T> implements Serializable {
private static final long serialVersionUID = -4843781544193464186L;
private static Logger logger = LogManager.getLogger(GenericDAO.class);
protected Class<T> classe;
#PersistenceContext
protected transient EntityManager entityManager;
protected GenericDAO(final Class<T> classe) {
this.classe = classe;
}
public T save(final T entity) {
try {
entityManager.persist(entity);
entityManager.flush();
} catch (Exception e) {
logger.error("Falha ao persistir a entidade: " + entity.toString(), e);
throw TypeApplicationException.PERSISTENCIA.buildException("Ocorreu uma falha na persistencia");
}
return entity;
}
the class itemDAO that should use the base intrasis. In it I tried to use #PersistenceContext (unitName = "intrasis")
public class ItemDAO extends GenericDAO<Item> {
private static final long serialVersionUID = 1L;
#PersistenceContext(unitName="intrasis")
protected transient EntityManager entityManager;
protected ItemDAO() {
super(Item.class);
}
}
another class that uses the other bank and tbm I tried the PersistenceContext for the other bank.
public class CursoDAO extends GenericDAO<Curso> {
private static final long serialVersionUID = 5659645428769766934L;
#PersistenceContext(unitName="intranet")
protected transient EntityManager entityManager;
protected CursoDAO() {
super(Curso.class);
}
public List<Curso> buscarTodos() {
String jpql = "SELECT e FROM Curso e";
TypedQuery<Curso> typedQuery = entityManager.createQuery(jpql, Curso.class);
return typedQuery.getResultList();
}
1) You have probably an injection point where you don't specify the unit name. If it is not the case try adding this line to your persistence.xml :
<property name="wildfly.jpa.default-unit" value="true"/>
2) In your GenericDAO do not use:
#PersistenceContext
protected transient EntityManager entityManager;
try passing the entity manager througth constructor.

#Inject public com.netflix.appinfo.ApplicationInfoManager(EurekaInstanceConfig, InstanceInfo, OptionalArgs)

When deploying Spring Cloud-enabled services on JBoss, there are some error messages. The specific environmental information is as follows:
JBoss version :8.1
spring-cloud version:1.5.4
JDK:1.8
The specific error stack information is as follows:
2018-10-18 10:33:14,961 WARN [org.jboss.weld.Validator] (MSC service thread 1-7) WELD-001471: Interceptor method shutdown defined on class com.netflix.eureka.DefaultEurekaServerContext is not defined according to the specification. It should not throw java.lang.Exception, which is a checked exception.
2018-10-18 10:33:14,964 WARN [org.jboss.weld.Validator] (MSC service thread 1-7) WELD-001471: Interceptor method initialize defined on class com.netflix.eureka.DefaultEurekaServerContext is not defined according to the specification. It should not throw java.lang.Exception, which is a checked exception.
2018-10-18 10:33:14,970 WARN [org.jboss.weld.Validator] (MSC service thread 1-7) WELD-001471: Interceptor method shutdown defined on class com.netflix.eureka.aws.AwsBinderDelegate is not defined according to the specification. It should not throw java.lang.Exception, which is a checked exception.
2018-10-18 10:33:14,971 WARN [org.jboss.weld.Validator] (MSC service thread 1-7) WELD-001471: Interceptor method start defined on class com.netflix.eureka.aws.AwsBinderDelegate is not defined according to the specification. It should not throw java.lang.Exception, which is a checked exception.
2018-10-18 10:33:14,988 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-7) MSC000001: Failed to start service jboss.deployment.unit."backstage-server.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."backstage-server.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_65]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_65]
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type InstanceInfo with qualifiers #Default
at injection point [BackedAnnotatedParameter] Parameter 2 of [BackedAnnotatedConstructor] #Inject public com.netflix.appinfo.ApplicationInfoManager(EurekaInstanceConfig, InstanceInfo, OptionalArgs)
at com.netflix.appinfo.ApplicationInfoManager.<init>(ApplicationInfoManager.java:0)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:368)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:289)
at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:135)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:166)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:514)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_65]
... 3 more
2018-10-18 10:33:15,021 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "backstage-server.war")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"backstage-server.war\".WeldStartService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"backstage-server.war\".WeldStartService: Failed to start service
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type InstanceInfo with qualifiers #Default
at injection point [BackedAnnotatedParameter] Parameter 2 of [BackedAnnotatedConstructor] #Inject public com.netflix.appinfo.ApplicationInfoManager(EurekaInstanceConfig, InstanceInfo, OptionalArgs)
at com.netflix.appinfo.ApplicationInfoManager.<init>(ApplicationInfoManager.java:0)
"}}
2018-10-18 10:33:15,070 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "backstage-server.war" (runtime-name : "backstage-server.war")
2018-10-18 10:33:15,086 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.deployment.unit."backstage-server.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."backstage-server.war".WeldStartService: Failed to start service

Unable to locate persistence units

In IntelliJ Idea I created a project with JPA 2.1 and hibernate 4.3.10 final. After I created a datasource (Test connection : Success) I generated persistence mapping from database. Project compiles without error. When I tried to test in JPA Console with a simple Select * query, it returns following exception:
[2015-05-21 16:01:27] javax.persistence.PersistenceException: Unable to locate persistence units
[2015-05-21 16:01:27] java.lang.RuntimeException: javax.persistence.PersistenceException: Invalid persistence.xml.
Error parsing XML [line : -1, column : -1] : cvc-elt.1: Cannot find the declaration of element 'persistence'.
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.validate(PersistenceXmlParser.java:377)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.loadUrl(PersistenceXmlParser.java:310)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.parsePersistenceXml(PersistenceXmlParser.java:114)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.doResolve(PersistenceXmlParser.java:104)
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.locatePersistenceUnits(PersistenceXmlParser.java:86)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:97)
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:88)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:69)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.intellij.jpa.remote.impl.JpaFacadeImpl.createEntityManagerFactory(JpaFacadeImpl.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$254(TCPTransport.java:683)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/4400315.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Here is the persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>model.DepartmentEntity</class>
<class>model.UserEntity</class>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/svgroup"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
Can someone tell me how to fix this error? I was searching and reading for about 10 hours without success
EDIT
If I try to deploy the app on wildfly without creating entities from database it will deploy the app. However, if I try to deploy the app after the entities are created i get the following error:
2015-05-21 18:13:01,697 INFO [org.hibernate.Version] (ServerService Thread Pool -- 15) HHH000412: Hibernate Core {4.3.7.Final}
2015-05-21 18:13:01,704 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 15) HHH000206: hibernate.properties not found
2015-05-21 18:13:01,711 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 15) HHH000021: Bytecode provider name : javassist
2015-05-21 18:13:02,183 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."SVGZad4_ejb_exploded.rar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."SVGZad4_ejb_exploded.rar".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "SVGZad4_ejb_exploded.rar"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration
at org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor.process(ParsedRaDeploymentProcessor.java:237)
at org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor.deploy(ParsedRaDeploymentProcessor.java:130)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.2.0.Final.jar:8.2.0.Final]
... 5 more
Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration
at org.jboss.jca.common.metadata.ra.common.ResourceAdapter1516Impl.validate(ResourceAdapter1516Impl.java:352)
at org.jboss.jca.common.metadata.ra.common.ConnectorAbstractmpl.validate(ConnectorAbstractmpl.java:334)
at org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor.process(ParsedRaDeploymentProcessor.java:206)
... 7 more
2015-05-21 18:13:02,207 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 3) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "SVGZad4_ejb_exploded.rar")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"SVGZad4_ejb_exploded.rar\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"SVGZad4_ejb_exploded.rar\".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment \"SVGZad4_ejb_exploded.rar\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration
Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration"}}
2015-05-21 18:13:02,216 ERROR [org.jboss.as.server] (management-handler-thread - 3) JBAS015870: Deploy of deployment "SVGZad4_ejb_exploded.rar" was rolled back with the following failure message:
{"JBAS014671: Failed services" => {"jboss.deployment.unit.\"SVGZad4_ejb_exploded.rar\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"SVGZad4_ejb_exploded.rar\".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment \"SVGZad4_ejb_exploded.rar\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration
Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration"}}
2015-05-21 18:13:02,301 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-1) HV000001: Hibernate Validator 5.1.3.Final
2015-05-21 18:13:02,626 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 15) JBAS011410: Stopping Persistence Unit (phase 1 of 2) Service 'SVGZad4_ejb_exploded.rar#NewPersistenceUnit'
2015-05-21 18:13:02,637 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015877: Stopped deployment SVGZad4_ejb_exploded.rar (runtime-name: SVGZad4_ejb_exploded.rar) in 422ms
2015-05-21 18:13:02,640 INFO [org.jboss.as.controller] (management-handler-thread - 3) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.deployment.unit."SVGZad4_ejb_exploded.rar".INSTALL
I think your Jars (JPA / Hibernate) are probably older.
What Jars are you using?
Usually when you download something like Hibernate, they allow you to download sample projects which have the example of such persistence.xml and other files.
Update
Maybe the app isn't picking up the expected persistence.xml file?
Try to add some obviously incorrect, invalid text in your persistence.xml file. This way, the exception will printed out with the complete name of the persitence.xml that is being looked at.
I think you have to change your persistence.xml
The following line
<property name = "hbm2ddl.auto" value = "update" />
must probably be changed to
<property name = "hibernate.hbm2ddl.auto" value = "update" />
Then I suppose you do not have any password in your database
<property name = "hibernate.connection.password" value = "?" />
Otherwise, I see nothing strange.

Categories

Resources