JBOSS AS7 7.1.1 - Entity not persisted and createNamedQuery fire exception

#1

I'm trying to have the guestbook example running in the following environment:

  • jboss as 7.1.1 final
  • oracle jdk 1.7.0_04
  • maven 3.0.4
  • objectdb 2.4.0_04 installed as a module of jboss

No IDE is used for building the Guestbook.war only maven.

 

My GuestDAO code is as follows:

package guest;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.NamedQuery;
import javax.persistence.NamedQueries;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;



@NamedQueries( {
@NamedQuery(
         name="Guest.getAll",
         query="select g from guest.Guest g order by g.name"
) } )
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class GuestDao {
    // Injected database connection:
@PersistenceContext(unitName = "guest-pu") private EntityManager em;

    // Stores a new guest
    public void persist(final Guest guest) {
  withinTransaction( "persist" );
  System.out.println( "will persist : "  + guest + "...."  );
        this.em.persist(guest);
  this.em.flush();
  System.out.println( "persisted: "  + guest );
  findAllGuests();
    }

    // Retrieves all the guests:
    public List<Guest> getAllGuests() {
  return findAllGuests();
    }

private void withinTransaction(final String methodName ) {
  javax.persistence.EntityTransaction et = em.getTransaction();
  if ( et.isActive() )
   System.out.println( methodName + " is within an active transaction" );
  else
   System.out.println( methodName + " is out of an active transaction" );
}

private List<Guest> findAllGuests() {
  withinTransaction("findAllGuests");
  javax.persistence.EntityTransaction et = em.getTransaction();

  javax.persistence.metamodel.ManagedType<Guest> type = em.getMetamodel().managedType(Guest.class);
  if ( type == null )     System.out.println( "ManagedType Guest not found"  );

  // NamedQuery does not work
  // TypedQuery<Guest> query = this.em.createNamedQuery( "Guest.getAll", Guest.class );

  TypedQuery<Guest> query = this.em.createQuery( "select g from guest.Guest g order by g.name", Guest.class);

  final List<Guest> guests =  query.getResultList();
  System.out.println( "persisted Guest count: " + guests.size() );

  return guests;
    }
}

I get an exception when I want to use a named query

@NamedQueries( {
@NamedQuery(
         name="Guest.getAll",
         query="select g from guest.Guest g order by g.name"
) } )

...

// NamedQuery does not work
// TypedQuery<Guest> query = this.em.createNamedQuery( "Guest.getAll", Guest.class );
// where as this query ok
TypedQuery<Guest> query = this.em.createQuery( "select g from guest.Guest g order by g.name", Guest.class);

I also struggle with the persisting part:

public void persist(final Guest guest) {

  System.out.println( "will persist : "  + guest + "...."  );
  this.em.persist(guest);
  this.em.flush();
  System.out.println( "persisted: "  + guest );
  findAllGuests();
}

 

The call to GuestDAO.persist produces the ouput :

18:51:13,454 INFO  [stdout] (http--127.0.0.1-8080-1) persisted Guest count: 0
18:51:18,219 INFO  [stdout] (http--127.0.0.1-8080-1) persist is within an active transaction
18:51:18,219 INFO  [stdout] (http--127.0.0.1-8080-1) will persist :  null:alice:2012-06-05....
18:51:18,235 INFO  [stdout] (http--127.0.0.1-8080-1) persisted:  19:alice:2012-06-05
18:51:18,235 INFO  [stdout] (http--127.0.0.1-8080-1) findAllGuests is within an active transaction
18:51:18,235 INFO  [stdout] (http--127.0.0.1-8080-1) persisted Guest count: 1

but immediately after getAllGuests is called and the output shows that no guest have been persisted ??

18:51:18,251 INFO  [stdout] (http--127.0.0.1-8080-1) findAllGuests is within an active transaction
18:51:18,251 INFO  [stdout] (http--127.0.0.1-8080-1) persisted Guest count: 0

any hint on what's going on ?

 

#2

Please post the full stack trace of the exception.

Have you tried running the tutorial guest book web application as is?

ObjectDB Support
#3

The tutorial code from http://www.objectdb.com/files/examples/guestbook-jee6.zip does not even deploy on JBOSS AS7

stack trace is:

09:40:30,202 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "Guestbook.war"
09:40:30,624 INFO  [org.jboss.as.jpa] (MSC service thread 1-1) JBAS011401: Read persistence.xml for GuestbookPU
09:40:30,655 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named GuestDao in deployment unit deployment "Guestbook.war" are as follows:

java:global/Guestbook/GuestDao!guest.GuestDao
java:app/Guestbook/GuestDao!guest.GuestDao
java:module/GuestDao!guest.GuestDao
java:global/Guestbook/GuestDao
java:app/Guestbook/GuestDao
java:module/GuestDao

09:40:30,671 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC00001: Failed to start service jboss.deployment.unit."Guestbook.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."Guestbook.war".INSTALL: Failed to process phase INSTALL of deployment "Guestbook.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_04]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_04]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_04]
Caused by: javax.persistence.PersistenceException: JBAS011466: PersistenceProvider 'com.objectdb.jpa.Provider' not found
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.lookupProvider(PersistenceUnitDeploymentProcessor.java:555)
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deployPersistenceUnit(PersistenceUnitDeploymentProcessor.java:295)
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.addPuService(PersistenceUnitDeploymentProcessor.java:258)
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.handleWarDeployment(PersistenceUnitDeploymentProcessor.java:194)
at org.jboss.as.jpa.processor.PersistenceUnitDeploymentProcessor.deploy(PersistenceUnitDeploymentProcessor.java:118)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more

The only way I found to be successful in the deployment is to add into the persistence.xml file

<property name="jboss.as.jpa.providerModule" value="com.objectdb" />

and declared objectdb-jee as a module into jboss.

Since the objectdb-jee is now a jboss module there is no more need to include it in the lib of the .war
having objectdb*.jar packaged within the war does not make any more difference.
so I've added the <packagingExcludes> in the pom.xml when building the war

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <packagingExcludes>WEB-INF/lib/objectdb*.jar</packagingExcludes>
    </configuration>
</plugin>

 

The example now runs but Guest still dont get persisted. No exception either. Some cache misconfiguration ?

 

As for the NamedQuery problem the full stack trace is:

10:01:22,960 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/Guestbook].[jsp]] (http--127.0.0.1-8080-1) "Servlet.service()" pour la servlet jsp a généré une exception: com.objectdb.o.UserException: Failed to open file '/C:/apps4dev/jboss-as-7.1.1.Final/bin/content/Guestbook.war/WEB-INF/classes/'
at com.objectdb.o.MSG.d(MSG.java:61) [objectdb-jee-2.4.0_04.jar:]
at com.objectdb.o.UNH.n(UNH.java:318) [objectdb-jee-2.4.0_04.jar:]
at com.objectdb.o.UNH.m(UNH.java:275) [objectdb-jee-2.4.0_04.jar:]
at com.objectdb.o.SCM.x(SCM.java:476) [objectdb-jee-2.4.0_04.jar:]
at com.objectdb.o.TYS.z(TYS.java:781) [objectdb-jee-2.4.0_04.jar:]
at com.objectdb.o.TYM.ad(TYM.java:506) [objectdb-jee-2.4.0_04.jar:]
at com.objectdb.o.TYM.ac(TYM.java:470) [objectdb-jee-2.4.0_04.jar:]
at com.objectdb.o.TYM.aE(TYM.java:1239) [objectdb-jee-2.4.0_04.jar:]
at com.objectdb.jpa.EMImpl.createNamedQuery(EMImpl.java:809) [objectdb-jee-2.4.0_04.jar:]
at org.jboss.as.jpa.container.AbstractEntityManager.createNamedQuery(AbstractEntityManager.java:79) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at guest.GuestDao.getAllGuests(GuestDao.java:23) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_04]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_04]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_04]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_04]
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:36) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:47) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:32) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]
at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]
at guest.GuestDao$$$view7.getAllGuests(Unknown Source) [classes:]
at guest.GuestServlet.doGet(GuestServlet.java:24) [classes:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:706) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:677) [jbossweb-7.0.13.Final.jar:]
at org.apache.jsp.index_jsp._jspService(index_jsp.java:55)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jbossweb-7.0.13.Final.jar:]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253) [jbossweb-7.0.13.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_04]

I obtained it by annoting GuestDao with :

@NamedQuery( name="getAllGuests", query="SELECT g FROM Guest g ORDER BY g.id" )

and replacing

TypedQuery<Guest> query = em.createQuery( "SELECT g FROM Guest g ORDER BY g.id", Guest.class);

by

TypedQuery<Guest> query = em.createNamedQuery( "getAllGuests", Guest.class);

The full code of GuestDAO becomes:

package guest;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.NamedQuery;

@NamedQuery( name="getAllGuests", query="SELECT g FROM Guest g ORDER BY g.id" )
@Stateless
public class GuestDao {
    // Injected database connection:
    @PersistenceContext private EntityManager em;

    // Stores a new guest:
    public void persist(Guest guest) {
        em.persist(guest);
    }

    // Retrieves all the guests:
    public List<Guest> getAllGuests() {
        TypedQuery<Guest> query = em.createNamedQuery( "getAllGuests", Guest.class);
        // TypedQuery<Guest> query = em.createQuery( "SELECT g FROM Guest g ORDER BY g.id", Guest.class);
        return query.getResultList();
    }
}
#4

The exception indicates a class loading issue, which may be caused by using ObjectDB as a JBoss module (which has never been checked and is not supported).

Try using the Guestbook from this forum thread, in post #6 (and also see post #9).

As you can see in that forum thread - running ObjectDB in JBoss this way should work.

ObjectDB Support
#5

* @NamedQuery issue

Whether the application is running on jboss as7 (7.1.1.Final)  or running on glassfish 3.1.2

I get similar exception when using createNamedQuery

glassfish stack trace

Caused by: java.lang.IllegalArgumentException: com.objectdb.o.UserException: Unknown named query 'Guest.getAll' (no definition is found)
at com.objectdb.o.JPE.g(JPE.java:109)
at com.objectdb.o.ERR.f(ERR.java:60)
at com.objectdb.o.OBC.onObjectDBError(OBC.java:1504)
at com.objectdb.jpa.EMImpl.createNamedQuery(EMImpl.java:826)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNamedQuery(EntityManagerWrapper.java:566)


Caused by: com.objectdb.o.UserException: Unknown named query 'Guest.getAll' (no definition is found)
at com.objectdb.o.MSG.d(MSG.java:61)
at com.objectdb.o.TYM.aE(TYM.java:1249)
at com.objectdb.jpa.EMImpl.createNamedQuery(EMImpl.java:809)

* entities are not getting persisted

I get the problem with jboss as 7.1.1.Final but not with glassfish 3.1.2

I had already checked the forum thread you mentioned. The issues were not the same (deployment failure). The version of JBoss was 7.0.x at that time and lots of declaration were also missing in the persistence.xml file:

objectdb as a provider and the provider module and thus to have objectdb installed as a jpa module of jboss. Maybe that was not required with JBoss 7.0.x but  thats the only way I found with jboss 7.1 to have the application be deployed correctly and runs.

...
<provider>com.objectdb.jpa.Provider</provider>
...
<properties>
<property name="jboss.as.jpa.providerModule" value="com.objectdb" />

<property name="javax.persistence.jdbc.url" value="...
...
</properties>

 

 

 

#6

I've finally figured out what was wrong with the NamedQuery

The JPA spec said that the annotation should be used on the entity class and not the ejb class.

So I annoted the Guest class but still called the createNamedQuery from the GuestDAO

@Entity
@NamedQueries( {
@NamedQuery(
  name="Guest.findByName",
  query="select g from guest.Guest g where g.name = :name order by g.name"
),
@NamedQuery(
  name="Guest.findAll",
  query="select g from guest.Guest g order by g.name"
) } )
public class Guest implements Serializable, Comparable<Guest> {

..

 

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class GuestDao {
    // Injected database connection:
@PersistenceContext(unitName = "guest-pu") private EntityManager em;

    // Stores a new guest
    public void persist(final Guest guest) {
  Guest persistedGuest = findByName( guest.getName() );
  if ( persistedGuest == null ) {
   this.em.persist(guest);
  }
    }

    // Retrieves all the guests:
public List<Guest> findAll() {

  final TypedQuery<Guest> query = this.em.createNamedQuery( "Guest.findAll", Guest.class );
  final List<Guest> guests =  query.getResultList();
  return guests;
    }

public Guest findByName( final String name ) {
  Guest guest = null;
  if ( name != null ) {
   TypedQuery<Guest> query = this.em.createNamedQuery( "Guest.findByName", Guest.class )
    .setParameter( "name", name.toLowerCase() );
   final List<Guest> guests =  query.getResultList();
   if ( guests.size() > 0 ) guest = guests.get(0);
  }
  return guest;
    }
}

 

The persistence issue on jboss as 7.1.1.Final still remains.

 

#7

Attempt to deploy the application results in a strange:

JBAS014777:   Services which failed to start:      service jboss.module.service."deployment.guestbook.war".main: org.jboss.msc.service.StartException in service jboss.module.service."deployment.guestbook.war".main: Failed to load module: deployment.guestbook.war:main

09:14:52,546 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.module.service.\"deployment.guestbook.war\".main" => "org.jboss.msc.service.StartException in service jboss.module.service.\"deployment.guestbook.war\".main: Failed to load module: deployment.guestbook.war:main"}}}}

Maybe solving this exception requires setting a JBoss module as you wrote.

Could you please provide more details (and attach relevant files) on how exactly you set your JBoss environment?

ObjectDB Support
#8

I have setup objectdb as module named "com.objectdb" in jboss:

/jboss-as7.1.1.Final/modules/com/objectdb/main
- module.xml
- objectdb-jee-2.4.0_04.jar

 

module.xml:

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.1" name="com.objectdb">
    <resources>
        <resource-root path="objectdb-jee-2.4.0_04.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.persistence.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.validation.api"/>
        <module name="javax.servlet.api" optional="true"/>
     </dependencies>
</module>

 

The pom.xml is modified accordingly so that no objectdb lib is packaged within the war

 

...
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${plugin-war.version}</version>
    <configuration>
     <failOnMissingWebXml>false</failOnMissingWebXml>
     <packagingExcludes>WEB-INF/lib/objectdb*-${objectdb.version}.jar</packagingExcludes>
     <!--
      exclude objectdb-jee when application is packaged for jboss
      objectdb-jee-${objectdb.version}.jar shall be added as a jboss module
     -->
    </configuration>
   </plugin>
...

 

persistence.xml shall declares <jta-data-source> and <property name="jboss.as.jpa.providerModule" value="com.objectdb" />

<?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="guest-pu" transaction-type="JTA">
     <description>ObjectDB Persistence Unit</description>
      <provider>com.objectdb.jpa.Provider</provider>
  <!-- default available JTA data source available in JBOSS AS 7.1.1 Final
  <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
  -->
      <class>guest.Guest</class>
  <properties>
   <!-- objectdb has to be installed as a module in JBOSS AS7 -->
      <property name="jboss.as.jpa.providerModule" value="com.objectdb" />
  
   <property name="objectdb.home" value="D:/databases" />
   <property name="javax.persistence.jdbc.url" value="objectdb:D:/databases/guests.odb"/>
   <!-- locking issue with glassfish. objectdb log file remains lock when application is undeployed !
   => better have the log file located outside the application
   <property name="javax.persistence.jdbc.url" value="$objectdb/db/guests.odb"/>
   -->
         <property name="javax.persistence.jdbc.user" value="admin"/>
         <property name="javax.persistence.jdbc.password" value="admin"/>
      </properties>
</persistence-unit>

</persistence>

 

 

#9

I noticed that by changing the PersistenceContext to EXTENDED which also causes to change the GuestDAO from @Stateless to @Stateful, the guestbook application works with JBoss-AS7. Guest entity are correctly persisted.

@Stateful
// @Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class GuestDao {
    // Injected database connection:
 @PersistenceContext(unitName = "guest-pu", type=PersistenceContextType.EXTENDED ) private EntityManager em;
 // @PersistenceContext(unitName = "guest-pu" ) private EntityManager em;

This workaround is of course not satisfying: changing all the @Stateless ejb of an real world jee application into @Stateful ejb is not reasonable.

Maybe some configuration can be done at JTA or cache level of JBoss in the jboss configuration file or persistence.xml file ?

The standalone.xml configuration file contains the following section, I dont know if it is related with the issue.

<subsystem xmlns="urn:jboss:domain:infinispan:1.2" default-cache-container="hibernate">
            <cache-container name="hibernate" default-cache="local-query">
                <local-cache name="entity">
                    <transaction mode="NON_XA"/>
                    <eviction strategy="LRU" max-entries="10000"/>
                    <expiration max-idle="100000"/>
                </local-cache>
                <local-cache name="local-query">
                    <transaction mode="NONE"/>
                    <eviction strategy="LRU" max-entries="10000"/>
                    <expiration max-idle="100000"/>
                </local-cache>
                <local-cache name="timestamps">
                    <transaction mode="NONE"/>
                    <eviction strategy="NONE"/>
                </local-cache>
            </cache-container>
        </subsystem>

 

#10

Thank you for the update.

Unfortunately every new version of JBoss includes updates that break portability with other software products. This is not just a JBoss-ObjectDB problem but also JBoss-Eclipse, JBoss-NetBeans (no support of JBoss 7 in NetBeans yet), etc.

ObjectDB was adjusted to JBoss 6, then to JBoss 7.02, and now it has to be adjusted to JBoss 7.1.1.

This will be done, but not immediately. Meanwhile please consider using JBoss 7.02.

ObjectDB Support
#11

I've found that the guestbook example is not working on JBoss AS 7.1.1

when the GuestDAO is

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class GuestDao {
    @PersistenceContext(unitName = "guest-pu" ) private EntityManager em;

but it is working when the EntityManagerFactory gets injected instead of the EntityManager

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class GuestDao {

@PersistenceUnit(unitName = "guest-pu" ) private EntityManagerFactory emf;

public EntityManager getEntityManager() {
  return this.emf.createEntityManager();
}
...

or the persistence context type is EXTENDED and the SessionBean Stateful instead of Stateless

@Stateful
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class GuestDao {

@PersistenceContext(unitName = "guest-pu", type=PersistenceContextType.EXTENDED ) private EntityManager em;
...

 

It would be appreciated if you could indicate in a page of the site the JEE application servers and release on
which objectdb (and release) have been tested with success or not.

In my opiniion the indication "Tested with Tomcat, Jetty, GlassFish, JBoss and Spring"
at page http://www.objectdb.com/object/db/database/overview is too generic.

 

 

#12

Update: Version 2.4.3 fixes the problem of accessing ObjectDB from a stateless EJB.

ObjectDB Support

Reply