Deploy on glassfish server : no suitable driver for jdbc:derby - maven

When I try to upload a maven spring project which uses JPA (I use derby) on a server, I receive an error he didn't find an suitable driver for jdbc:derby :
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [service.LocationGuide]: Constructor threw exception; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:derby://xxx.xxx.xxx.xx:portnbr/leuvenspeaks;create=true Error Code: 0.
I used these dependecies for JPA and derby
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.10.2.0</version>
</dependency>
And my Persistence unit :
<persistence version="2.1" 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">
<persistence-unit name="LocationPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>domain.Location</class>
<class>domain.Story</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby://xxx.xxx.xxx.xxx:portnbr/leuvenspeaks;create=true"/>
<property name="javax.persistence.jdbc.user" value="xxxx"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
<property name="javax.persistence.jdbc.password" value="xxxx"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
Thanks in advance!!

Put derby driver into $GLASSFISH_HOME\glassfish\domains\domain1\lib folder and restart server.
You can download Derby driver from here

Related

cargo-maven3-plugin: unable to add datasource

I am trying to configure datasources on a Tomcat using Cargo to allow people doing local tests of the software.
When I start the application using cargo, I have the following error:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mosesEntityManagerFactory' defined in class path resource [app-logic.xml]: Cannot resolve reference to bean 'appDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appDataSource' defined in class path resource [logic-datasource.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jdbc/app] is not bound in this Context. Unable to find [jdbc].
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:334)
...
The cargo maven plugin is configured in this way:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven3-plugin</artifactId>
<version>1.10.4</version>
<configuration>
<container>
<containerId>tomcat7x</containerId>
<zipUrlInstaller>
<url>https://repo.maven.apache.org/maven2/org/apache/tomcat/tomcat/7.0.55/tomcat-7.0.55.zip</url>
</zipUrlInstaller>
<timeout>600000</timeout>
<output>${project.build.directory}/tomcat7x/container.log</output>
<append>false</append>
<log>${project.build.directory}/tomcat7x/cargo.log</log>
<dependencies>
[...] some dependencies like mysql, etc...
</dependencies>
</container>
<configuration>
<type>standalone</type>
<home>${project.build.directory}/tomcat7x/catalina-base</home>
<properties>
<cargo.jvmargs>-Xmx4096m</cargo.jvmargs>
<cargo.datasource.datasource.mysql>
cargo.datasource.driver=com.mysql.jdbc.Driver|
cargo.datasource.url=jdbc:mysql://server:3306/app|
cargo.datasource.jndi=jdbc/app|
cargo.datasource.username=ignore|
cargo.datasource.password=ignore
</cargo.datasource.datasource.mysql>
</properties>
<configfiles>
<configfile>
<file>${project.basedir}/src/test/resources/tomcat7/tomcat-users.xml</file>
<todir>conf</todir>
</configfile>
<configfile>
<file>${project.basedir}/src/test/resources/tomcat7/context.xml</file>
<todir>conf</todir>
</configfile>
</configfiles>
</configuration>
</configuration>
</plugin>
The context.xml I provide contains:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
<ResourceLink global="jdbc/app" name="jdbc/app" type="javax.sql.DataSource" />
</Context>
and the logic-datasource.xml mentioned in the exception contains:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="appDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/app" />
</bean>
</beans>
I didn't find a way to debug what's happening by myself.
Do you know what is wrong looking at the configuration or how can I check what cargo is doing?
Thanks

HHH000342: Could not obtain connection to query metadata : Unable to construct requested dialect [org.hibernate.dialect.DB2400Dialect]

My build is successful but deployment using Wildfly 16 on Windows is failing. On my macbook it works.
Windows OpenJDK 1.8.0_252.
Macbook OpenJDK 1.8.0_251
Wildfly 16 configurations such as drivers on Windows and my Mac are equal.
Does anyone here have a clue? What am I missing.
Thanks in advance for your attention. Your help is much appreciated.
applicationContext.xml
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="YYY" />
<property name="persistenceXmlLocation" value="classpath:persistence.xml" />
<property name="dataSource" ref="yyyDataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.DB2400Dialect" />
</bean>
</property>
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property>
</bean>
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="YYY" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/jdbc/xxx/YYYDB</jta-data-source>
<class>nl.xxxx.xx.xxx.xxx</class>
<class>nl.xxxx.xx.xxx.xxx</class>
<properties>
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DB2400Dialect" />
<!--<property name="javax.persistence.sharedCache.mode" value="ALL"/> -->
</properties>
</persistence-unit>
</persistence>
pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.4.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.4.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws</artifactId>
<version>2.1.4.RELEASE</version>
<classifier>all</classifier>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.2.2.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-aop</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
standalone.xml
<datasource jta="true" jndi-name="java:/jdbc/xxx/YYYDB" pool-name="YYYDB" enabled="true" use-ccm="false">
<connection-url>jdbc:db2://xxxxxx.xxx.net:xxxx/xxxxx</connection-url>
<driver-class>com.ibm.db2.jcc.DB2Driver</driver-class>
<driver>db2</driver>
<new-connection-sql>SELECT current date FROM sysibm.sysdummy1</new-connection-sql>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<max-pool-size>5</max-pool-size>
</pool>
<security>
<user-name>yyy02</user-name>
<password>${VAULT::vault::yyy02::1}</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
Stacktrace
09:27:44,076 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "xxxx-services-ear.ear")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.subunit.\"xxxx-services-ear.ear\".\"xxxxx-services-xxx.war\".undertow-deployment" => "java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.HibernateException: Unable to construct requested dialect [org.hibernate.dialect.DB2400Dialect]
Caused by: java.lang.ClassCastException: org.hibernate.dialect.DB2400Dialect cannot be cast to org.hibernate.dialect.Dialect"}}
09:27:44,077 ERROR [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0021: Deploy of deployment "xxxx-services-ear.ear" was rolled back with the following failure message:
{"WFLYCTL0080: Failed services" => {"jboss.deployment.subunit.\"xxxx-services-ear.ear\".\"xxxx-services-xxx.war\".undertow-deployment" => "java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.HibernateException: Unable to construct requested dialect [org.hibernate.dialect.DB2400Dialect]
Caused by: java.lang.ClassCastException: org.hibernate.dialect.DB2400Dialect cannot be cast to org.hibernate.dialect.Dialect"}}
09:27:44,089 DEBUG [org.jboss.as.ejb3.deployment] (MSC service thread 1-8) unRegistering EJB client context for classloader ModuleClassLoader for Module "deployment.xxxx-services-ear.ear" from Service Module Loader
09:27:44,091 DEBUG [org.jboss.as.ejb3.deployment] (MSC service thread 1-5) unRegistering EJB client context for classloader ModuleClassLoader for Module "deployment.xxxx-services-ear.ear.xxxx-services-xxx.war" from Service Module Loader
09:27:44,095 DEBUG [org.wildfly.extension.batch] (MSC service thread 1-1) Removing batch environment; ModuleClassLoader for Module "deployment.xxxx-services-ear-.ear.xxxx-services-xxx.war" from Service Module Loader
09:27:44,111 DEBUG [org.infinispan.manager.DefaultCacheManager] (MSC service thread 1-7) Stopping cache manager null on null
09:27:44,118 DEBUG [org.infinispan.manager.DefaultCacheManager] (MSC service thread 1-7) Stopped cache manager null
09:27:44,118 DEBUG [org.jboss.as.clustering.infinispan] (MSC service thread 1-7) frontend-services-cache cache container stopped
09:27:44,462 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0208: Stopped subdeployment (runtime-name: xxxx-services-xxx.war) in 383ms
09:27:44,951 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0028: Stopped deployment xxxx-services-ear.ear (runtime-name: frontend-services-ear-2.21.0-SNAPSHOT.ear) in 873ms
[2020-07-28 09:27:45,090] Artifact xxxxx-services-ear:ear: Error during artifact deployment. See server log for details.
[2020-07-28 09:27:45,091] Artifact xxxxx-services-ear.ear: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.deployment.subunit.\"xxxxx-services-ear.ear\".\"xxxx-services-xxx.war\".undertow-deployment" => "java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Caused by: org.hibernate.HibernateException: Unable to construct requested dialect [org.hibernate.dialect.DB2400Dialect]
Caused by: java.lang.ClassCastException: org.hibernate.dialect.DB2400Dialect cannot be cast to org.hibernate.dialect.Dialect"}}
09:27:52,669 INFO [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0272: Suspending server
09:27:52,677 INFO [org.jboss.as.ejb3] (management-handler-thread - 1) WFLYEJB0493: EJB subsystem suspension complete
09:27:52,680 DEBUG [org.jboss.remoting.remote.connection] (management I/O-2) JBREM000200: Remote connection failed: java.io.IOException: An existing connection was forcibly closed by the remote host
09:27:52,682 INFO [org.jboss.as.server] (Management Triggered Shutdown) WFLYSRV0241: Shutting down in response to management operation 'shutdown'
I think it is a class loading problem.
First of all, Wildfly 16 uses version 5.3.9.Final of hibernate, so you should change your pom to this version. Secondly, all these hibernate jars are automatically provided by Wildfly, so they should be with scope provided in your pom.xml because you shouldn't include them in your final war/ear file.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.3.9.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.9.Final</version>
<scope>provided</scope>
</dependency>
<dependency>

Run JPA using Maven and Intellij IDEA 12

I have just switch over to Intellij IDEA and I am trying to test my JPA entities using a RESOURCE_LOCAL persistence unit. My environment is currently using EclipseLink, MySQL and Maven.
At the moment my test class is performing the following call:
EntityManagerFactory factory = Persistence.createEntityManagerFactory("app-test");
The persistence unit is being detected (if I change the name in the persistence.xml file, I get an error saying the unit cannot be found). However, if I run the test I am getting the following errors in the console:
Exception in thread "main" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader#1005354a
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [app-test] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:115)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at suite.Suite.main(Suite.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [app-test] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1541)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1532)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:105)
... 8 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [app-test] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:221)
... 12 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.hasEntity(MetadataProject.java:1272)
at org.eclipse.persistence.internal.jpa.metadata.accessors.objects.MetadataAnnotatedElement.isOneToMany(MetadataAnnotatedElement.java:610)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.buildAccessor(ClassAccessor.java:594)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessorFields(ClassAccessor.java:423)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessors(ClassAccessor.java:395)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.preProcess(ClassAccessor.java:1178)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor.preProcess(MappedSuperclassAccessor.java:724)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.preProcess(EntityAccessor.java:555)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage1(MetadataProject.java:1649)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:531)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:550)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1469)
... 10 more
This is my persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence version="2.0" 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" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="app-test" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/app" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="FINEST" />
<property name="eclipselink.logging.level.sql" value="FINEST" />
<property name="eclipselink.logging.parameters" value="true" />
</properties>
</persistence-unit>
</persistence>
My pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.app.entities</groupId>
<artifactId>app-entities</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>app-entities</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.24</version>
</dependency>
</dependencies>
</project>
My folder structure (all my entities are in the src/main/java folder):
I removed the project and recreated it from scratch and it is working now.

Exception while trying to use #PersistenceContext with unitName

I am using Spring 3.1, JPA 2 with Hibernate, JBoss. I want to use multiple persistence units. Here is my persistence.xml
<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="pu1">
<jta-data-source>java:jboss/datasources/ds1</jta-data-source>
<properties>
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/em1" />
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
<persistence-unit name="pu2">
<jta-data-source>java:jboss/datasources/ds2</jta-data-source>
<properties>
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/em2" />
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
</persistence>
When I am trying to create the EntityManager with the unitName like this
#PersistenceContext(unitName="pu1")
I am getting exception,
16:56:35,834 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-1) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'languageDAOImpl': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'pu1' is defined
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342) [spring-orm-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
I am doing anything wrong? If I have only one persistence unit and if I use #PersistenceContext without unitName it is working fine.
I dont know how to setup and work with multiple persistence units.

is java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSessionFactory with mybatis and Spring

I'm new to Mybatis and trying to implement mybatis with Spring but getting the below runtime error while starting tomcat.
Here is my pom.xml
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.0.0</version>
</dependency>
and application context:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="uactivityDS"/>
<property name="configLocation" value="classpath:mybatis-config.xml"/>
</bean>
The error is:
the resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSessionFactory
The mybatis-spring-1.0.0.jar file exists in war/web-inf/lib, though.
Any idea what's going on in this scenario?
If you look at the pom.xml for mybatis-spring-1.0.0.jar, it has a compile time dependency of mybatis 3.0.4 which contains the class org/apache/ibatis/session/SqlSessionFactory.
So include that jar as well along with others mentioned in the pom.xml and you should be good.

Resources