No Persistence provider for EntityManager in RCP Pulgin Project - jpa

I am getting a
No Persistence provider for EntityManager for named X
in an RCP Plugin application I am working on. I have used hibernate as ORM and javax.persistence. I am using Derby for my database. I have grouped all the hibernate Jar and supporting jars into a plugin and added to the current project i am woking on. I am at my wits end. Any help would be appreciated. i have as of now looked at different places for answers but not found any.
I have placed the Persistence.xml file in the classpath under/META-INF/persistence.xml. I have tried placing the persistence.xml at these location - /RCMSecond/src/persistence.xml and /RCMSecond/src/META-INF/persistence.xml and /RCMSecond/META-INF/persistence.xml still the RCP project is throwing the same error stacktrace.
persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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="RCMSecond" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>entity.ColumnMeta</class>
<class>entity.DataBase_CompositeID</class>
<class>entity.Files</class>
<class>entity.Database</class>
<class>entity.LookUpCols</class>
<class>entity.Project</class>
<class>entity.QueryEntity</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
<property name="hibernate.archive.autodetection" value="class, hbm" />
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:simpleDB;create=true" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<property name="eclipselink.logging.level" value="SEVERE" />
<property name="show_sql" value="true" />
<property name="format_sql" value="true"></property>
</properties>
</persistence-unit>
</persistence>
GenericDAOImpl.java
package daoImpl;
import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.TypedQuery;
import org.hibernate.Criteria;
import org.hibernate.Session;
import dao.GenericDAO;
import exceptions.EntityNotPresent;
public class GenericDAOImpl < T, ID extends Serializable > implements GenericDAO < T, ID > {
protected EntityManager entityManager;
protected EntityTransaction entityTransaction;
public GenericDAOImpl() {
super();
EntityManagerFactory factory = Persistence.createEntityManagerFactory("RCMSecond");
this.entityManager = factory.createEntityManager();
entityTransaction = this.entityManager.getTransaction();
}
#
Override
public T save(T t) {
entityTransaction.begin();
entityManager.persist(t);
entityManager.flush();
entityTransaction.commit();
return t;
}
#
SuppressWarnings({
"unchecked", "rawtypes"
})# Override
public List < T > readAll(String namedQueryName, Class clazz) {
TypedQuery < T > query = entityManager.createNamedQuery(namedQueryName, clazz);
return query.getResultList();
}
#
SuppressWarnings("unchecked")# Override
public T readById(#SuppressWarnings("rawtypes") Class clazz, ID id) {
entityTransaction.begin();
T t = (T) entityManager.find(clazz, id);
entityTransaction.commit();
return t;
}
#
Override
public T update(#SuppressWarnings("rawtypes") Class clazz, ID id, T updated) throws EntityNotPresent {
if (isEntityExists(clazz, id)) {
entityManager.merge(updated);
return updated;
} else {
throw new EntityNotPresent("Entity Not found, So Could not be updated");
}
}
#
Override
public void delete(#SuppressWarnings("rawtypes") Class clazz, ID removeId) {
if (isEntityExists(clazz, removeId)) {
T old = readById(clazz, removeId);
entityTransaction.begin();
entityManager.remove(old);
entityTransaction.commit();
}
}
#
SuppressWarnings("unchecked")# Override
public boolean isEntityExists(#SuppressWarnings("rawtypes") Class clazz, ID id) {
return entityManager.find(clazz, id) != null;
}
#
SuppressWarnings("unchecked")# Override
public T getFirstRecord(Class <? > clazz) {
entityTransaction.begin();
Session session = entityManager.unwrap(Session.class);
Criteria queryCriteria = session.createCriteria(clazz);
queryCriteria.setFirstResult(0);
queryCriteria.setMaxResults(1);
T t = (T) queryCriteria.list().get(0);
entityTransaction.commit();
return t;
}
#
Override
public List < T > getByQuery(String queryExecute, Object[] pars, #SuppressWarnings("rawtypes") Class clazz) {
entityTransaction.begin();#
SuppressWarnings("unchecked")
TypedQuery < T > query = entityManager.createQuery(queryExecute, clazz);
for (int i = 0; i < pars.length; i++) {
query.setParameter("arg" + i, pars[i]);
}
List < T > results = query.getResultList();
entityTransaction.commit();
return results;
}
}
StackTrace
org.eclipse.e4.core.di.InjectionException: javax.persistence.PersistenceException: No Persistence provider
for EntityManager named RCMSecond
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java: 68)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java: 898)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java: 121)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java: 345)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java: 264)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java: 162)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java: 104)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java: 73)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java: 55)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java: 129)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java: 971)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 640)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 746)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java: 717)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java: 711)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java: 42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java: 695)
at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java: 1306)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer$1.handleEvent(LazyStackRenderer.java: 72)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java: 40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java: 186)
at org.eclipse.swt.widgets.Display.syncExec(Display.java: 4761)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java: 211)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java: 36)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java: 197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java: 197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java: 1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java: 230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java: 148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java: 135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java: 78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java: 39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java: 85)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java: 59)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java: 374)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java: 171)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.postProcess(LazyStackRenderer.java: 108)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 658)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 746)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java: 717)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java: 711)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java: 42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java: 695)
at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java: 71)
at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java: 151)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 654)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 746)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java: 717)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java: 711)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java: 42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java: 695)
at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java: 71)
at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveRenderer.processContents(PerspectiveRenderer.java: 49)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 654)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 746)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java: 717)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java: 711)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java: 42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java: 695)
at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveStackRenderer.showTab(PerspectiveStackRenderer.java: 82)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer$1.handleEvent(LazyStackRenderer.java: 72)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java: 40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java: 186)
at org.eclipse.swt.widgets.Display.syncExec(Display.java: 4761)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java: 211)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java: 36)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java: 197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java: 197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java: 1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java: 230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java: 148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java: 135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java: 78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java: 39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java: 85)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java: 59)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java: 374)
at org.eclipse.e4.ui.model.application.ui.advanced.impl.PerspectiveStackImpl.setSelectedElement(PerspectiveStackImpl.java: 135)
at org.eclipse.e4.ui.model.application.ui.advanced.impl.PerspectiveStackImpl.setSelectedElement(PerspectiveStackImpl.java: 1)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.postProcess(LazyStackRenderer.java: 108)
at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveStackRenderer.postProcess(PerspectiveStackRenderer.java: 63)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 658)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 746)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java: 717)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java: 711)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java: 42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java: 695)
at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java: 71)
at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer.processContents(WBWRenderer.java: 614)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 654)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java: 746)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java: 717)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java: 711)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java: 42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java: 695)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java: 1057)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java: 337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java: 1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java: 156)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java: 159)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java: 196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java: 134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java: 104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java: 380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java: 235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java: 608)
at org.eclipse.equinox.launcher.Main.run(Main.java: 1515)
at org.eclipse.equinox.launcher.Main.main(Main.java: 1488)
Caused by: javax.persistence.PersistenceException: No Persistence provider
for EntityManager named RCMSecond
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java: 61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java: 39)
at daoImpl.GenericDAOImpl. < init > (GenericDAOImpl.java: 30)
at daoImpl.DatabaseDAOImpl. < init > (DatabaseDAOImpl.java: 14)
at com.view.FirstView.createControls(FirstView.java: 31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java: 56)
...112 more
I have tried placing the persistence.xml at these location - /RCMSecond/src/persistence.xml** and **/RCMSecond/src/META-INF/persistence.xml still the RCP project is throwing the same error stacktrace.

https://docs.oracle.com/javaee/7/tutorial/persistence-intro003.htm
The JAR file or directory whose META-INF directory contains
persistence.xml is called the root of the persistence unit. The scope
of the persistence unit is determined by the persistence unit's root.
Persistent units can be packaged as part of a WAR or EJB JAR file or
can be packaged as a JAR file that can then be included in an WAR or
EAR file.
• If you package the persistent unit as a set of classes in an EJB JAR
file, persistence.xml should be put in the EJB JAR's META-INF directory.
• If you package the persistence unit as a set of classes in a WAR file,
persistence.xml should be located in the WAR file's
WEB-INF/classes/META-INF directory.
• If you package the persistence unit in a JAR file that will be
included in a WAR or EAR file, the JAR file should be located in either
- the WEB-INF/lib directory of a WAR Or
- the EAR file's library directory
Check configuration. Your Eclipse should be able to map resource files and build all packages. check Project->Properties->Build Path in order to configure project dependencies.
offtopic tips:
You are trying to obtain the EntityManager by injection:
#PersistenceContext
protected EntityManager entityManager
Then to obtain the EntityManager from the EntityManagerFactory instance:
EntityManagerFactory factory = Persistence.createEntityManagerFactory("RCMSecond");
this.entityManager = factory.createEntityManager();

Related

java.lang.NoSuchFieldError: FSYNCED

I am getting error when executing below code, could you please help me in resolving this error
public fun getEntityManager(): EntityManager {
val tm: TransactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager()
val emf: EntityManagerFactory = Persistence.createEntityManagerFactory(
"mongo-ogm")
tm.begin()
return emf.createEntityManager()
}
Caused by: java.lang.NoSuchFieldError: FSYNCED
at org.hibernate.ogm.datastore.mongodb.options.WriteConcernType.(WriteConcernType.java:37)
at org.hibernate.ogm.datastore.mongodb.options.impl.WriteConcernOption.(WriteConcernOption.java:29)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.lang.Class.newInstance(Class.java:584)
at org.hibernate.ogm.options.navigation.source.impl.ConfigurationOptionValueSource$ConfigurationBasedOptionContainer.getAll(ConfigurationOptionValueSource.
java:82)
<persistence-unit name="mongo-ogm" transaction-type="JTA">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>com.ogm.model.UserEntity</class>
<properties>
<property name="hibernate.ogm.datastore.provider" value="mongodb"/>
<property name="hibernate.ogm.datastore.database" value="demo"/>
<property name="hibernate.ogm.mongodb.host" value="localhost"/>
<property name="hibernate.ogm.mongodb.username" value=""/>
<property name="hibernate.ogm.mongodb.password" value=""/>
<!-- <property name="" value="localhost"/>-->
<property name="hibernate.search.default.directory_provider" value="filesystem"/>
<property name="hibernate.search.default.indexBase" value="/tmp/.hibernate_ogm_demo_luceneindexes"/>
</properties>
</persistence-unit>
implementation("org.hibernate.ogm:hibernate-ogm-mongodb:5.4.1.Final")
implementation("org.mongodb:mongodb-driver-reactivestreams:4.0.5")
implementation("org.jboss.narayana.jta:narayana-jta:5.8.1.Final")
implementation("org.jboss:jboss-transaction-spi:7.6.0.Final")
Usually this issue occurs when you have dependency mismatch.
I suspect you have more than one version of hibernate-ogm-mongodb in you classpath.
hibernate-ogm-mongodb:5.4.1.Final contains enum WriteConcernType.FSYNCED(WriteConcern.FSYNCED)
Run gradle dependencies | grep hibernate-ogm-mongodb, verify if you have more than one version of the library as dependency.
Exclude older/other versions from other dependencies in your build.gradle file.

PostgreSQL + OpenJPA: exception when calling persist()

I'm using OpenJPA 2.4.2 to access a PostgreSQL database from an ejb.
When calling persist (see the code below) I get the following exception:
<openjpa-2.4.2-r422266:1777108 fatal general error> org.apache.openjpa.persistence.PersistenceException: user lacks privilege or object not found: NEXTVAL {SELECT NEXTVAL('employee_id_seq')} [code=-5501, state=42501]
org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:5003)
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4963)
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:133)
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:107)
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:59)
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:63)
org.apache.openjpa.util.ImplHelper.generateValue(ImplHelper.java:159)
org.apache.openjpa.util.ImplHelper.generateFieldValue(ImplHelper.java:143)
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignField(JDBCStoreManager.java:774)
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:492)
org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:468)
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:758)
org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:135)
org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:595)
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:3051)
org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:44)
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1072)
org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2143)
org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2103)
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:2021)
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:527)
org.apache.geronimo.transaction.manager.TransactionImpl.beforeCompletion(TransactionImpl.java:512)
org.apache.geronimo.transaction.manager.TransactionImpl.beforePrepare(TransactionImpl.java:413)
org.apache.geronimo.transaction.manager.TransactionImpl.commit(TransactionImpl.java:262)
org.apache.geronimo.transaction.manager.TransactionManagerImpl.commit(TransactionManagerImpl.java:252)
org.apache.openejb.core.transaction.JtaTransactionPolicy.completeTransaction(JtaTransactionPolicy.java:331)
org.apache.openejb.core.transaction.TxRequired.commit(TxRequired.java:76)
org.apache.openejb.cdi.transactional.InterceptorBase.intercept(InterceptorBase.java:68)
org.apache.openejb.cdi.transactional.RequiredInterceptor.intercept(RequiredInterceptor.java:35)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.webbeans.component.InterceptorBean.intercept(InterceptorBean.java:136)
org.apache.webbeans.intercept.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:63)
org.apache.webbeans.intercept.DefaultInterceptorHandler.invoke(DefaultInterceptorHandler.java:139)
com.virtualpairprogrammers.staffmanagement.dataaccess.EmployeeDataAccessImplementation$$OwbInterceptProxy0.insert(com/virtualpairprogrammers/staffmanagement/dataaccess/EmployeeDataAccessImplementation.java)
com.virtualpairprogrammers.staffmanagement.EmployeeManagementImplementation.registerEmployee(EmployeeManagementImplementation.java:22)
com.virtualpairprogrammers.backingbeans.AddEmployeeBean.AddEmployee(AddEmployeeBean.java:45)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.apache.el.parser.AstValue.invoke(AstValue.java:247)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
org.apache.webbeans.el22.WrappedMethodExpression.invoke(WrappedMethodExpression.java:52)
org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
javax.faces.component.UICommand.broadcast(UICommand.java:120)
javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1174)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:365)
javax.faces.component.UIViewRoot._process(UIViewRoot.java:1660)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:864)
org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:42)
org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:196)
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:143)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.openejb.server.httpd.EEFilter.doFilter(EEFilter.java:65)
Here is how I call persist and define the persistence context:
#Transactional
public class EmployeeDataAccessImplementation implements EmployeeDataAccess
{
#PersistenceContext(unitName = "EmployeeDB")
private EntityManager em;
...
public void insert(Employee newEmployee) {
em.persist(newEmployee);
}
}
Here is how I configure the persistence unit EmployeeDB in persistence.xml:
<?xml version="1.0"?>
<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="EmployeeDB">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>com.virtualpairprogrammers.staffmanagement.domain.Employee</class>
<properties>
<property name="persistence.openjpa.ConnectionDriverName" value="org.postgresql.Driver"/>
<property name="persistence.openjpa.ConnectionURL" value="jdbc:postgresql://localhost:5432/EmployeeDB"/>
<property name="persistence.openjpa.ConnectionUserName" value="postgres"/>
<property name="persistence.openjpa.ConnectionPassword" value="test"/>
<property name="openjpa.Log" value="SQL=TRACE"/>
<property name="openjpa.jdbc.DBDictionary" value="postgres(SchemaCase=lower)"/>
</properties>
</persistence-unit>
Finally, here is how I map the class Employee to the database table Employee:
#Entity(name="employee")
public class Employee {
#Id
#GeneratedValue (strategy = GenerationType.SEQUENCE, generator="employee_gen")
#SequenceGenerator (name="employee_gen", sequenceName="employee_id_seq", allocationSize=1)
#Getter #Setter
private Long id;
...
public Employee() {}
}
I've created the sequence employee_id_seq using the following SQL command:
create sequence employee_id_seq;
Just in case I've changed the owner and granted all the priviledges on employee_id_seq to postgres:
alter sequence public.employee_id_seq OWNER TO postgres;
GRANT USAGE, SELECT ON SEQUENCE employee_id_seq TO postgres;
I will appreciate your help.

Table/View does not exist in JavaEE web app deployed on Glassfish

I tried to deploy a JavaEE Web app with JPA persistence on a Glassfish server I installed on an Amazon EC2 instance. Everything worked fine for the deployment and for web pages rendering in my browser, but when I try to use persistence the result is the error "Table/View 'ATHLETE' does not exist'.
This is the first time I try to develop a web app with JPA and I'm trying to create a skeleton to use in the future for we app, but I think I'm missing a fundamental part. Also, using #GeneratedValue for the #Id I get a SEQUENCE table missing error. I'm afraid the two problems are related
The Athlete.java
package com.storassa.javaee.scuolesci;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
#Entity
#NamedQuery(name = "findAllAthletes", query = "SELECT b FROM Athlete b")
public class Athlete {
static int idRaw; // I use this to avoid the #GeneratedValue issue
#Id
int id;
String name, surname;
int birth;
public Athlete () {
idRaw++;
id = idRaw;
}
<getters and setters>
}
The AthleteEjb.java
package com.storassa.javaee.scuolesci;
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Startup;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.annotation.sql.*;
#LocalBean
#Stateless
public class AthleteEJB {
#PersistenceContext(unitName="scuoleSciPU")
private EntityManager em;
public List<Athlete> findAthlete() {
Query query = em.createNamedQuery("findAllAthletes");
return query.getResultList();
}
public Athlete createAthlete(Athlete athlete) {
em.persist(athlete);
return athlete;
}
}
The persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
version="2.1">
<persistence-unit name="scuoleSciPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.storassa.javaee.scuolesci.Athlete</class>
<properties>
<property name="eclipselink.target-database" value="DERBY" />
<property name="eclipselink.jdbc.driver"
value="org.apache.derby.jdbc.ClientDriver" />
<property name="eclipselink.jdbc.url"
value="jdbc:derby://localhost:1527;create=true" />
<property name="eclipselink.jdbc.user" value="APP" />
<property name="eclipselink.jdbc.password" value="APP" />
<property name="eclipselink.ddl-generation" value=" drop-and-create-tables" />
<property name="eclipselink.logging.level" value="INFO" />
<property name="eclipselink.deploy-on-startup" value="true" />
</properties>
</persistence-unit>
</persistence>
The error returned on the browser
type Exception report
message Internal Server Error
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.ejb.EJBException: Transaction aborted
root cause
javax.faces.el.EvaluationException: javax.ejb.EJBException: Transaction aborted
root cause
javax.ejb.EJBException: Transaction aborted
root cause
javax.transaction.RollbackException: Transaction marked for rollback.
root cause
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Table/View 'ATHLETE' does not exist.
Error Code: -20001
Call: INSERT INTO ATHLETE (ID, BIRTH, NAME, SURNAME) VALUES (?, ?, ?, ?)
bind => [4 parameters bound]
Query: InsertObjectQuery(com.storassa.javaee.scuolesci.Athlete#65fd5648)
root cause
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Table/View 'ATHLETE' does not exist.
Error Code: -20001
Call: INSERT INTO ATHLETE (ID, BIRTH, NAME, SURNAME) VALUES (?, ?, ?, ?)
bind => [4 parameters bound]
Query: InsertObjectQuery(com.storassa.javaee.scuolesci.Athlete#65fd5648)
root cause
java.sql.SQLSyntaxErrorException: Table/View 'ATHLETE' does not exist.
root cause
org.apache.derby.client.am.SqlException: Table/View 'ATHLETE' does not exist.
I don't provide web-related resource/classes as I don't think they can be useful. In case let me know.
Should the table ATHLETE be created due to the #Entity annotation and the ?
I guess the problem is related to leading space in eclipselink.ddl-generation value. In other words try to replace:
<property name="eclipselink.ddl-generation" value=" drop-and-create-tables" />
with
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />

Configuration JUnit 4 in Spring + eclipse

I'm trying to learn how to make tests with JUnit in Spring. I have written this test:
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.blah.baseProject.database.model.Usuario;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "file:src/test/resources/test-applicationContext.xml" })
public class LoginTest2 {
#Autowired
UsuarioDAO usuario;
private final static Logger logger = Logger.getLogger(LoginTest2.class);
#Test
public void test() {
logger.info("hi "+usuario.findAll());
}
}
But I get this error:
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener#54e063d] to prepare test instance [com.blah.baseProject.LoginTest2#457b9183]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:105)
at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:74)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDataSource': Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:608)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 25 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
This is my applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<!-- JDBC Data Source -->
<jee:jndi-lookup id="myDataSource" jndi-name="java:comp/env/jdbc/rhcimax"/>
<!-- Hibernate Session Factory -->
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="packagesToScan">
<array>
<value>com.blah.baseProject</value>
</array>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
</value>
</property>
</bean>
<!-- Hibernate Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<!-- Activates annotation based transaction management -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:component-scan base-package="com.blah.baseProject">
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
</beans>
I'm pretty lost with all this, any help will be appreciated.
Edit:
This is my UsuarioDAO:
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.blah.baseProject.database.DAO.UsuarioDAO;
import com.blah.baseProject.database.model.Usuario;
#Repository(value="UsuarioDao")
public class UsuarioHibernateDAO implements UsuarioDAO{
#Autowired
private SessionFactory mySessionFactory;
public void insert(Usuario user) {
mySessionFactory.getCurrentSession().save(user);
}
public void update(Usuario user) {
mySessionFactory.getCurrentSession().update(user);
}
/**
* #Transactional annotation below will trigger Spring Hibernate transaction manager to automatically create
* a hibernate session. See src/main/webapp/servlet-context.xml
*/
#Transactional
public List<Usuario> findAll() {
return mySessionFactory.getCurrentSession().createQuery("from Usuario").list();
}
public Usuario findById(String idUser) {
return (Usuario) mySessionFactory.getCurrentSession().load(Usuario.class, idUser);
}
public void delete(Usuario user) {
mySessionFactory.getCurrentSession().delete(user);
}
}
EDIT2:
//src/main/webapp/WEB-INF/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<!-- JDBC Data Source-->
<jee:jndi-lookup id="myDataSource" jndi-name="java:comp/env/jdbc/rhcimax"/>
<!-- Hibernate Session Factory -->
<bean id="mySessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="packagesToScan">
<array>
<value>com.blah.baseProject.test</value>
</array>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
</value>
</property>
</bean>
<!-- Hibernate Transaction Manager -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<!-- Activates annotation based transaction management -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:component-scan base-package="com.blah.baseProject.test">
<context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
</beans>
//src/main/test/resources/test-applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<!-- JDBC Data Source. It is assumed you have MySQL running on localhost port 3306 with
username root and blank password. Change below if it's not the case -->
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/rhcimax"/>
<property name="username" value="root"/>
<property name="password" value="1234"/>
<property name="validationQuery" value="SELECT 1"/>
</bean>
</beans>
//loginTest2.java
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.blah.baseProject.database.DAO.UsuarioDAO;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/applicationContext.xml", "classpath:test-applicationContext.xml" })
public class LoginTest2 {
#Autowired
UsuarioDAO usuarioDao;
private final static Logger logger = Logger.getLogger(LoginTest2.class);
#Test
public void test() {
logger.info("hi "+usuarioDao.findAll());
}
}
New Exception:
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener#67beff98] to prepare test instance [com.blah.baseProject.test.LoginTest2#2c7e895e]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.blah.baseProject.test.LoginTest2': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.blah.baseProject.database.DAO.UsuarioDAO com.blah.baseProject.test.LoginTest2.usuarioDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.blah.baseProject.database.DAO.UsuarioDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:376)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:312)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.blah.baseProject.database.DAO.UsuarioDAO com.blah.baseProject.test.LoginTest2.usuarioDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.blah.baseProject.database.DAO.UsuarioDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:514)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
... 26 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.blah.baseProject.database.DAO.UsuarioDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:986)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:856)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
... 28 more
INFO : org.springframework.context.support.GenericApplicationContext - Closing org.springframework.context.support.GenericApplicationContext#1f427975: startup date [Thu Aug 22 09:22:47 VET 2013]; root of context hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#2af0b852: defining beans [myDataSource,mySessionFactory,transactionManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,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.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
SOLUTION:
My test:
import java.util.List;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import com.blah.baseProject.database.DAO.UsuarioDAO;
import com.blah.baseProject.database.model.Usuario;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/applicationContext.xml", "classpath:test-applicationContext.xml" })
#TransactionConfiguration(transactionManager="transactionManager")
public class LoginTest2 extends AbstractTransactionalJUnit4SpringContextTests {
#Autowired
UsuarioDAO usuarioDao;
private final static Logger logger = Logger.getLogger(LoginTest2.class);
#Test
public void test() {
List<Usuario> a = usuarioDao.findAll();
logger.info("hi "+a.get(0).getLogin());
}
}
test-applicationContext.xml and applicationContext.xml remain the same as those specified in the edits to this question.
Your test configuration should only override the beans you don't have in your test (i.e. your datasource). Next you should use the classpath: prefix to load your test configuration file.
Change your test-applicationContext.xml file to the following, which will override the datasource in your applicationContext.xml
<!-- JDBC Data Source. It is assumed you have MySQL running on localhost port 3306 with
username root and blank password. Change below if it's not the case -->
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/myDb"/>
<property name="username" value="root"/>
<property name="password" value="1234"/>
<property name="validationQuery" value="SELECT 1"/>
</bean>
Now in your testcase load both files
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations = { "classpath:applicationContext.xml", "classpath:test-applicationContext.xml" })
public class LoginTest2 { ... }
The problem with your current setup is that your test-configuration.xml is a (bad) copy of your applicationContext.xml, which is something you should avoid. If you are writing tests you should also load your normal applicationContext.xml file(s) and override the beans you don't need.

GWT RCP - SerializationException

Started a new project from scratch, converted to JPA, my persistence provider is EclipseLink, added the necessary libraries (eclipselink.jar, eclipselink.jar, javax.persistence, mysql-connector-java-5.1). Tested the connection, ping ok. Then created a new package New > JPA > Entities from Tables > Selected all Entities and Key generator > Identity.
GestorIpca.java
GestorIpcaService.util.getInstance().getLista(new AsyncCallback<ArrayList<Docente>>() {
#Override
public void onFailure(Throwable caught) {
Window.alert("Erro na Ligacao efectuada");
caught.getStackTrace();
}
#Override
public void onSuccess(ArrayList<Docente> result) {
Window.alert("Ligacao efectuada com sucesso:" + result.size());
}
});
GestorIpcaService
#RemoteServiceRelativePath("greet")
public interface GestorIpcaService extends RemoteService {
String greetServer(String name) throws IllegalArgumentException;
public static class util{
public static GestorIpcaServiceAsync instance;
public static GestorIpcaServiceAsync getInstance(){
if(instance == null){
instance = GWT.create(GestorIpcaService.class);
}
return instance;
}
}
public ArrayList<Docente> getLista() throws IllegalArgumentException;
}
GestorIpcaServiceAsync
public interface GestorIpcaServiceAsync {
void greetServer(String input, AsyncCallback<String> callback)
throws IllegalArgumentException;
void getLista(AsyncCallback<ArrayList<Docente>> callback);
}
GestorIpcaServiceImpl
#SuppressWarnings("serial")
public class GestorIpcaServiceImpl extends RemoteServiceServlet implements
GestorIpcaService {
public ArrayList<Docente> getLista() throws IllegalArgumentException {
//Criamos um EntityManager
EntityManager em = JpaUtil.getEntityManagerFactory().createEntityManager();
//Criamos a consulta
String consulta = "SELECT r from Docente r";
//Executamos a consulta
Query q = em.createQuery(consulta);
ArrayList<Docente> lista = new ArrayList<Docente>(q.getResultList());
return lista;
}
/* public static void main(String args[]){
GestorIpcaServiceImpl serviceImpl = new GestorIpcaServiceImpl();
for (Docente docente : serviceImpl.getLista()){
System.out.println("nome: " + docente.getNome());
}
}
*/
In this file i tried to run as > Java Application and in Console showed me 2 records.
Package com.GestorIpca.factory
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class JpaUtil {
private static final EntityManagerFactory emf;
//Método estático
static{
//BLoco try
try
{
//Criação de EntityManagerFactory
emf = Persistence.createEntityManagerFactory("GestorIpca");
}catch (Throwable e){
//Controlar as excepções
System.err.println("A criação de SessionFactory falhou" + e);
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
}
public static EntityManagerFactory getEntityManagerFactory(){
return emf;
}
}
My persistence.xml was created automatically. Placed inside META-INF
<?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="GestorIpca">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.GestorIpca.shared.Ano</class>
<class>com.GestorIpca.shared.Categoria</class>
<class>com.GestorIpca.shared.Curso</class>
<class>com.GestorIpca.shared.Disciplina</class>
<class>com.GestorIpca.shared.Disponibilidade</class>
<class>com.GestorIpca.shared.Docente</class>
<class>com.GestorIpca.shared.Sala</class>
<class>com.GestorIpca.shared.Semestre</class>
<class>com.GestorIpca.shared.TipoCurso</class>
<class>com.GestorIpca.shared.Turma</class>
<class>com.GestorIpca.shared.User</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/timetable"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="k771u3"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
</properties>
</persistence-unit>
</persistence>
Last step > Run as > Web Application
Error > Could not connect to database and print a stack trace in Eclipse Console
[EL Info]: 2011-05-09 10:03:08.78--ServerSession(8068087)--EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20110202-r8913
[EL Info]: 2011-05-09 10:03:09.297--ServerSession(8068087)--file:/C:/Users/Martinho/WorkSpace/GestorIpca/war/WEB-INF/classes/_GestorIpca login successful
Starting Jetty on port 8888
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.client.rpc.SerializationException: java.lang.reflect.InvocationTargetException
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeWithCustomSerializer(ServerSerializationStreamWriter.java:764)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:727)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:616)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
at com.google.gwt.user.server.rpc.RPC.encodeResponse(RPC.java:616)
at com.google.gwt.user.server.rpc.RPC.encodeResponseForSuccess(RPC.java:474)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:571)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeWithCustomSerializer(ServerSerializationStreamWriter.java:746)
... 30 more
Caused by: com.google.gwt.user.client.rpc.SerializationException: Type 'org.eclipse.persistence.indirection.IndirectSet' was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.: instance = {IndirectSet: not instantiated}
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:614)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:704)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:734)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:616)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter$ValueWriter$8.write(ServerSerializationStreamWriter.java:152)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeValue(ServerSerializationStreamWriter.java:534)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeClass(ServerSerializationStreamWriter.java:704)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serializeImpl(ServerSerializationStreamWriter.java:734)
at com.google.gwt.user.server.rpc.impl.ServerSerializationStreamWriter.serialize(ServerSerializationStreamWriter.java:616)
at com.google.gwt.user.client.rpc.impl.AbstractSerializationStreamWriter.writeObject(AbstractSerializationStreamWriter.java:126)
at com.google.gwt.user.client.rpc.core.java.util.Collection_CustomFieldSerializerBase.serialize(Collection_CustomFieldSerializerBase.java:45)
at com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer.serialize(ArrayList_CustomFieldSerializer.java:38)
... 35 more
[ERROR] 500 - POST /gestoripca/greet (127.0.0.1) 57 bytes
Request headers
Host: 127.0.0.1:8888
Connection: keep-alive
Referer: http://127.0.0.1:8888/GestorIpca.html?gwt.codesvr=127.0.0.1:9997
Content-Length: 132
Origin: http://127.0.0.1:8888
X-GWT-Module-Base: http://127.0.0.1:8888/gestoripca/
X-GWT-Permutation: HostedMode
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.30 Safari/534.30
Content-Type: text/x-gwt-rpc; charset=UTF-8
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response headers
Content-Type: text/plain
Note: I changed in package com.GestorIpca.shared all my classes generated from tables
public class Ano implements Serializable
to
public class Ano implements IsSerializable
changed also my GestorIpca.gwt.xml and added this lines in end
<extend-configuration-property name="rpc.blacklist" value="com.google.gwt.user.client.ui.*Collection"/>
<extend-configuration-property name="rpc.blacklist" value="-.*List"/>
<extend-configuration-property name="rpc.blacklist" value="-.*Map"/>
<extend-configuration-property name="rpc.blacklist" value="-.*Collection"/>
<extend-configuration-property name="rpc.blacklist" value="+java.util.HashMap"/>
<extend-configuration-property name="rpc.blacklist" value="+java.util.LinkedHashMap"/>
<extend-configuration-property name="rpc.blacklist" value="+java.util.ArrayList"/>
What am i missing?
I depends on how your entities were defined. Maybe there are connections that GWT RPC doesn´t like. in this case i´d suggest create DTO´s or implement RequestFactory
Without knowing what your entities look like I would guess from the exception that the reason is probably how your entities get enhanced by your persistence provider:
What this means for GWT RPC is that by the time the object is ready to be transferred over the wire, it actually isn't the same object that the compiler thought was going to be transferred, so when trying to deserialize, the GWT RPC mechanism no longer knows what the type is and refuses to deserialize it.
Cited from: http://code.google.com/intl/de-DE/webtoolkit/articles/using_gwt_with_hibernate.html
That article also suggests how to create DTOs to solve this problem.
I know this is a very old question, but I ran into this exact issue tonight.
GWT Serialization doesn't seem to like java.util.Set. I almost feel like it was confusing java.util.Set with org.eclipse.persistence.indirection.IndirectSet.
Once I switched Set to ArrayList, the error went away.