1 2 Previous Next 23 Replies Latest reply on Feb 5, 2011 6:15 AM by ilya40umov

    EntityManager is an interface, and JAXB can't handle interfaces

    samwun9988

      Hello,

       

      With Jboss 6.0.0.Final, I tried to deploy a war file to the AS. The application is use Webservices to expose the functionalities of EJB3 entities.

       

      Here is the error with its exceptions:

       

      *** DEPLOYMENTS IN ERROR: Name -> Error

       

       

      vfs:///C:/jboss-6.0.0.Final/server/default/deploy/houseware.war -> org.jboss.deployers.spi.DeploymentException: Error during deploy: vfs:///C:/jboss-6.0.0.Final/server/default/deploy/houseware.war

       

       

      DEPLOYMENTS IN ERROR:

        Deployment "vfs:///C:/jboss-6.0.0.Final/server/default/deploy/houseware.war" is in error due to the following reason(s): com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions

      javax.persistence.EntityManager is an interface, and JAXB can't handle interfaces.

              this problem is related to the following location:

                      at javax.persistence.EntityManager

                      at private javax.persistence.EntityManager au.com.houseware.ws.jaxws_asm.GetEntityManagerResponse._return

                      at au.com.houseware.ws.jaxws_asm.GetEntityManagerResponse

      javax.persistence.EntityManager does not have a no-arg default constructor.

              this problem is related to the following location:

                      at javax.persistence.EntityManager

                      at private javax.persistence.EntityManager au.com.houseware.ws.jaxws_asm.GetEntityManagerResponse._return

                      at au.com.houseware.ws.jaxws_asm.GetEntityManagerResponse

       

       

      Here are a list of java classes that I have created::

      RoleJpaController.java,  RoleWS.java

       

      RoleJpaController.java:


       

      @Stateless

      public class RoleJpaController  {

       

       

          private EntityManagerFactory emf = null;

       

       

          public RoleJpaController() {

              emf = Persistence.createEntityManagerFactory("housewarePU");

          }

       

       

          public EntityManager getEntityManager() {

              return emf.createEntityManager();

          }

      ....

       

       

      RoleWS.java:


      @WebService()

      @Stateless()

      public class rolews {

          @EJB

          private RoleJpaController ejbRef;

       

       

          @WebMethod(operationName = "getEntityManager")

          public EntityManager getEntityManager() {

              return ejbRef.getEntityManager();

          }

       

       

          @WebMethod(operationName = "create")

          public void create(@WebParam(name = "role")

          Role role) throws PreexistingEntityException, Exception {

              ejbRef.create(role);

          }

      ....

       

       

      Have I done anything wrong with the way how I use these java classes?

       

      Very appreciate for any suggestion and help.

      Sam

        • 1. EntityManager is an interface, and JAXB can't handle interfaces
          mp911de

          Hi Sam,

          you should not expose the EntityManager as Web-Method since it's bad design. A better approach is exposing a method, which returns the data you need.

          The root-problem is javax.persistence.EntityManager does not have a no-arg default constructor and since EntityManager is not Serializable that would be the next Problem.

           

          Best regards,

          Mark

          • 2. EntityManager is an interface, and JAXB can't handle interfaces
            samwun9988

            Hi Mark,

             

            Thank you for the suggestion.

            I made RoleJpaController implements Serializable interface, but it still gave me the same exception. Yes I guess it is not so obvious like that.

            How would you make EntityManager Serializable?

             

            Thanks

            Sam

            • 3. EntityManager is an interface, and JAXB can't handle interfaces
              nickarls

              Like Mark said, I think the root problem is that JAXB needs to instantiate stuff. And for that, it needs to be a concrete class with a no-args constructor.

              • 4. EntityManager is an interface, and JAXB can't handle interfaces
                samwun9988

                Opps... pardon me, I never though EntityManager is an interface .

                 

                Thank you very much for the hints.

                 

                I will see how it goes after I implemented a concrete class of EntityManager..

                 

                Thanks

                Sam

                • 5. EntityManager is an interface, and JAXB can't handle interfaces
                  nickarls

                  I will see how it goes after I implemented a concrete class of EntityManager..

                   

                  We're not holding our breaths ;-)

                  • 6. EntityManager is an interface, and JAXB can't handle interfaces
                    samwun9988

                    I still don't know how to implement this idea.

                     

                    Here is the RoleJpaController class using the EntityManager:

                     

                    @Stateless

                    public class RoleJpaController {

                       

                        private EntityManagerFactory emf;

                     

                     

                        public RoleJpaController() {

                            emf = Persistence.createEntityManagerFactory("housewarePU");

                        }

                     

                     

                        public EntityManager getEntityManager() {

                            return emf.createEntityManager();

                        }

                     

                     

                        public void create(Role role) throws PreexistingEntityException, Exception {

                            if (role.getUserList() == null) {

                                role.setUserList(new ArrayList<User>());

                            }

                            EntityManager em = null;

                            try {

                                em = getEntityManager();

                                em.getTransaction().begin();

                                List<User> attachedUserList = new ArrayList<User>();

                                for (User userListUserToAttach : role.getUserList()) {

                                    userListUserToAttach = em.getReference(userListUserToAttach.getClass(), userListUserToAttach.getUserId());

                                    attachedUserList.add(userListUserToAttach);

                                }

                                role.setUserList(attachedUserList);

                                em.persist(role);

                                for (User userListUser : role.getUserList()) {

                                    Role oldRoleOfUserListUser = userListUser.getRole();

                                    userListUser.setRole(role);

                                    userListUser = em.merge(userListUser);

                                    if (oldRoleOfUserListUser != null) {

                                        oldRoleOfUserListUser.getUserList().remove(userListUser);

                                        oldRoleOfUserListUser = em.merge(oldRoleOfUserListUser);

                                    }

                                }

                                em.getTransaction().commit();

                            } catch (Exception ex) {

                                if (findRole(role.getRoleId()) != null) {

                                    throw new PreexistingEntityException("Role " + role + " already exists.", ex);

                                }

                                throw ex;

                            } finally {

                                if (em != null) {

                                    em.close();

                                }

                            }

                        }

                    ...

                     

                     

                    Thanks

                    Sam

                    • 7. Re: EntityManager is an interface, and JAXB can't handle interfaces
                      welle

                      Read the first reply from Mark again!

                       

                      > you should not expose the EntityManager as Web-Method since it's bad design.

                      > A better approach is exposing a method, which returns the data you need.

                       

                      Do not expose the getEntityManager method (I can't see why you wish to do that)

                       

                      Keep the create method exposed:

                       

                          @WebMethod(operationName = "create")

                          public void create(@WebParam(name = "role")

                       

                      Isn't that what you want to expose?

                      • 8. EntityManager is an interface, and JAXB can't handle interfaces
                        samwun9988

                        Hi Anders,

                         

                        Thank you for your response.

                        I actually have removed the @WebMethod on the getEntityManager method, but the exception still happened.

                         

                        Here is the RoleWS.java file:

                         

                        @WebService()

                        @Stateless()

                        public class rolews {

                            @EJB

                            private RoleJpaController ejbRef;

                         

                            public EntityManager getEntityManager() {

                                return ejbRef.getEntityManager();

                            }

                         

                         

                            @WebMethod(operationName = "create")

                            public void create(@WebParam(name = "role")

                            Role role) throws PreexistingEntityException, Exception {

                                ejbRef.create(role);

                            }

                         

                         

                            @WebMethod(operationName = "edit")

                            public void edit(@WebParam(name = "role")

                            Role role) throws IllegalOrphanException, NonexistentEntityException, Exception {

                                ejbRef.edit(role);

                            }

                         

                         

                            @WebMethod(operationName = "destroy")

                            public void destroy(@WebParam(name = "id")

                            Integer id) throws IllegalOrphanException, NonexistentEntityException {

                                ejbRef.destroy(id);

                            }

                         

                         

                            @WebMethod(operationName = "findRoleEntities")

                            public List<Role> findRoleEntities() {

                                return ejbRef.findRoleEntities();

                            }

                         

                         

                            @WebMethod(operationName = "findRoleEntities_1")

                            @RequestWrapper(className = "findRoleEntities_1")

                            @ResponseWrapper(className = "findRoleEntities_1Response")

                            public List<Role> findRoleEntities(@WebParam(name = "maxResults")

                            int maxResults, @WebParam(name = "firstResult")

                            int firstResult) {

                                return ejbRef.findRoleEntities(maxResults, firstResult);

                            }

                         

                         

                            @WebMethod(operationName = "findRole")

                            public Role findRole(@WebParam(name = "id")

                            Integer id) {

                                return ejbRef.findRole(id);

                            }

                         

                         

                            @WebMethod(operationName = "getRoleCount")

                            public int getRoleCount() {

                                return ejbRef.getRoleCount();

                            }

                         

                         

                        }

                         

                        Thanks

                        Sam

                        • 9. Re: EntityManager is an interface, and JAXB can't handle interfaces
                          welle

                          Hmm.. Is it still saying "javax.persistence.EntityManager is an interface, and JAXB can't handle interfaces." or is someother class that it complains about now?

                           

                          A quick test would be to remove the method completely from rolews

                           

                          <!--

                          public EntityManager getEntityManager() {

                                  return ejbRef.getEntityManager();

                              }

                          -->

                           

                          Can't see why you need it anyway!

                          • 10. EntityManager is an interface, and JAXB can't handle interfaces
                            samwun9988

                            Anders,

                             

                            Thank you for your suggesiton, you are right, it is the problem with the getEntityManager(). I have to removed it.

                            Now another error shown up:

                             

                            22:53:30,119 INFO  [org.jboss.wsf.stack.cxf.metadata.MetadataBuilder] Add Service

                            id=userws

                            address=http://localhost:8080/houseware/userws

                            implementor=au.com.houseware.ws.userws

                            invoker=org.jboss.wsf.stack.cxf.InvokerEJB3

                            serviceName={http://ws.houseware.com.au/}userwsService

                            portName={http://ws.houseware.com.au/}userwsPort

                            wsdlLocation=null

                            mtomEnabled=false

                            22:53:30,121 INFO  [org.jboss.wsf.stack.cxf.metadata.MetadataBuilder] Add Service

                            id=rolews

                            address=http://localhost:8080/houseware/rolews

                            implementor=au.com.houseware.ws.rolews

                            invoker=org.jboss.wsf.stack.cxf.InvokerEJB3

                            serviceName={http://ws.houseware.com.au/}rolewsService

                            portName={http://ws.houseware.com.au/}rolewsPort

                            wsdlLocation=null

                            mtomEnabled=false

                            22:53:30,135 INFO  [org.jboss.wsf.framework.management.DefaultEndpointRegistry] register: jboss.ws:context=houseware,endpoint=userws

                            22:53:30,145 INFO  [org.jboss.wsf.framework.management.DefaultEndpointRegistry] register: jboss.ws:context=houseware,endpoint=rolews

                            22:53:30,796 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] Creating Service {http://ws.houseware.com.au/}userwsService from class au.com.houseware.ws.userws

                            22:53:32,625 INFO  [org.apache.cxf.endpoint.ServerImpl] Setting the server's publish address to be http://localhost:8080/houseware/userws

                            22:53:33,303 INFO  [org.jboss.wsf.stack.cxf.deployment.WSDLFilePublisher] WSDL published to: file:/C:/jboss-6.0.0.Final/server/default/data/wsdl/houseware.war/userwsService.wsdl

                            22:53:33,314 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] Creating Service {http://ws.houseware.com.au/}rolewsService from class au.com.houseware.ws.rolews

                            22:53:33,473 INFO  [org.apache.cxf.endpoint.ServerImpl] Setting the server's publish address to be http://localhost:8080/houseware/rolews

                            22:53:33,532 INFO  [org.jboss.wsf.stack.cxf.deployment.WSDLFilePublisher] WSDL published to: file:/C:/jboss-6.0.0.Final/server/default/data/wsdl/houseware.war/rolewsService.wsdl

                            22:53:33,544 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Created KernelDeployment for: houseware.war

                            22:53:33,551 INFO  [org.jboss.ejb3.deployers.JBossASKernel] installing bean: jboss.j2ee:jar=houseware.war,name=RoleJpaController,service=EJB3

                            22:53:33,551 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   with dependencies:

                            22:53:33,551 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and demands:

                            22:53:33,552 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss-switchboard:appName=houseware,module=houseware; Required: Create

                            22:53:33,553 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described

                            22:53:33,553 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and supplies:

                            22:53:33,553 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jndi:RoleJpaController

                            22:53:33,586 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Added bean(jboss.j2ee:jar=houseware.war,name=RoleJpaController,service=EJB3) to KernelDeployment of: houseware.war

                            22:53:33,590 INFO  [org.jboss.ejb3.deployers.JBossASKernel] installing bean: jboss.j2ee:jar=houseware.war,name=UserJpaController,service=EJB3

                            22:53:33,591 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   with dependencies:

                            22:53:33,591 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and demands:

                            22:53:33,591 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss-switchboard:appName=houseware,module=houseware; Required: Create

                            22:53:33,592 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described

                            22:53:33,592 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and supplies:

                            22:53:33,592 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jndi:UserJpaController

                            22:53:33,593 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Added bean(jboss.j2ee:jar=houseware.war,name=UserJpaController,service=EJB3) to KernelDeployment of: houseware.war

                            22:53:33,625 INFO  [org.jboss.ejb3.deployers.JBossASKernel] installing bean: jboss.j2ee:jar=houseware.war,name=rolews,service=EJB3

                            22:53:33,625 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   with dependencies:

                            22:53:33,626 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and demands:

                            22:53:33,627 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss-switchboard:appName=houseware,module=houseware; Required: Create

                            22:53:33,627 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described

                            22:53:33,627 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss-injector:topLevelUnit=houseware.war,unit=houseware.war,bean=rolews; Required: Described

                            22:53:33,627 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and supplies:

                            22:53:33,627 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jndi:rolews

                            22:53:33,628 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Added bean(jboss.j2ee:jar=houseware.war,name=rolews,service=EJB3) to KernelDeployment of: houseware.war

                            22:53:33,631 INFO  [org.jboss.ejb3.deployers.JBossASKernel] installing bean: jboss.j2ee:jar=houseware.war,name=userws,service=EJB3

                            22:53:33,631 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   with dependencies:

                            22:53:33,632 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and demands:

                            22:53:33,632 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss-switchboard:appName=houseware,module=houseware; Required: Create

                            22:53:33,632 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described

                            22:53:33,632 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jboss-injector:topLevelUnit=houseware.war,unit=houseware.war,bean=userws; Required: Described

                            22:53:33,633 INFO  [org.jboss.ejb3.deployers.JBossASKernel]   and supplies:

                            22:53:33,633 INFO  [org.jboss.ejb3.deployers.JBossASKernel]     jndi:userws

                            22:53:33,634 INFO  [org.jboss.ejb3.deployers.JBossASKernel] Added bean(jboss.j2ee:jar=houseware.war,name=userws,service=EJB3) to KernelDeployment of: houseware.war

                            22:53:50,351 INFO  [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:jar=houseware.war,name=RoleJpaController,service=EJB3

                            22:53:50,392 INFO  [org.jboss.ejb3.EJBContainer] STARTED EJB: au.com.houseware.persistence.controller.RoleJpaController ejbName: RoleJpaController

                            22:53:50,400 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

                             

                             

                             

                             

                            22:53:50,403 WARN  [org.jboss.ejb3.TimerServiceContainer] EJBTHREE-2193: using deprecated TimerServiceFactory for restoring timers

                            22:53:50,909 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Start: name=jboss.j2ee:jar=houseware.war,name=RoleJpaController,service=EJB3 state=Create: java.lang.ClassCastException: org.hibernate.hql.ast.HqlToken cannot be cast to antlr.Token

                                    at antlr.CharScanner.makeToken(Unknown Source) [:6.0.0.Final]

                                    at org.hibernate.hql.ast.HqlLexer.makeToken(HqlLexer.java:62) [:3.6.0.Final]

                                    at org.hibernate.hql.antlr.HqlBaseLexer.mIDENT(HqlBaseLexer.java:599) [:3.6.0.Final]

                                    at org.hibernate.hql.antlr.HqlBaseLexer.nextToken(HqlBaseLexer.java:270) [:3.6.0.Final]

                                    at antlr.TokenBuffer.fill(Unknown Source) [:6.0.0.Final]

                                    at antlr.TokenBuffer.LA(Unknown Source) [:6.0.0.Final]

                                    at antlr.LLkParser.LA(Unknown Source) [:6.0.0.Final]

                                    at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:141) [:3.6.0.Final]

                                    at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:274) [:3.6.0.Final]

                                    at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182) [:3.6.0.Final]

                                    at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) [:3.6.0.Final]

                                    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101) [:3.6.0.Final]

                                    at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [:3.6.0.Final]

                                    at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124) [:3.6.0.Final]

                                    at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) [:3.6.0.Final]

                                    at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) [:3.6.0.Final]

                                    at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770) [:3.6.0.Final]

                                    at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:272) [:3.6.0.Final]

                                    at org.jboss.ejb3.timerservice.mk2.TimerServiceImpl.getActiveTimers(TimerServiceImpl.java:983) [:1.0.0-alpha-13]

                                    at org.jboss.ejb3.timerservice.mk2.TimerServiceImpl.restoreTimers(TimerServiceImpl.java:738) [:1.0.0-alpha-13]

                                    at org.jboss.ejb3.timerservice.mk2.TimerServiceFactoryImpl.restoreTimerService(TimerServiceFactoryImpl.java:123) [:1.0.0-alpha-13]

                                    at org.jboss.ejb3.TimerServiceContainer.restoreTimerService(TimerServiceContainer.java:244) [:1.7.17]

                                    at org.jboss.ejb3.TimerServiceContainer.afterStart(TimerServiceContainer.java:129) [:1.7.17]

                                    at org.jboss.ejb3.EJBContainer.start(EJBContainer.java:1113) [:1.7.17]

                                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_11]

                            ....

                             

                            ...

                             

                             

                            Do you know what caused this error?

                             

                            Thanks

                            Sam

                            • 11. EntityManager is an interface, and JAXB can't handle interfaces
                              nickarls

                              Are you packing any extra hibernate jars in your app?

                              • 12. EntityManager is an interface, and JAXB can't handle interfaces
                                samwun9988

                                Hi, yes, there are many Hibernate libs .

                                 

                                antlr-2.7.6.jar  commons-collections-2.1.1.jar  ehcache-1.2.3.jar                  hibernate-tools.jar  jta.jar

                                asm-attrs.jar    commons-logging-1.1.jar        hibernate-annotations.jar          hibernate3.jar

                                asm.jar          derbyclient.jar                hibernate-commons-annotations.jar  javassist.jar

                                cglib-2.1.3.jar  dom4j-1.6.1.jar                hibernate-entitymanager.jar        jdbc2_0-stdext.jar

                                 

                                 

                                Thanks

                                Sam

                                • 13. EntityManager is an interface, and JAXB can't handle interfaces
                                  nickarls

                                  Tip of the day: If you're not sure what you need, take out *all* libs, only package stuff that gives ClassNotFoundException at runtime...

                                  • 14. EntityManager is an interface, and JAXB can't handle interfaces
                                    samwun9988

                                    Thank you for the suggestion. I have tried to remove antr and hibernate3, but it caused tons of errors.

                                    As I searched in google for a while, and found the following suggesiton:

                                     

                                    https://issuetracker.springsource.com/browse/EBR-303

                                     

                                    However I don't know how to put that in my persistence.xml and hibernate.cfg.xml file.

                                     

                                    Here is my persistence.xml file:

                                     

                                    <?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="housewarePU" transaction-type="JTA">

                                        <jta-data-source>houseware</jta-data-source>

                                        <properties/>

                                      </persistence-unit>

                                    </persistence

                                     

                                    hibernate.cfg.xml file:

                                     

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

                                    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

                                    <hibernate-configuration>

                                      <session-factory>

                                        <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>

                                        <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>

                                        <property name="hibernate.connection.url">jdbc:derby://localhost:1527/sample</property>

                                        <property name="hibernate.connection.username">app</property>

                                        <property name="hibernate.connection.password">app</property>

                                      </session-factory>

                                    </hibernate-configuration>

                                     

                                    Thakns

                                    Sam

                                    1 2 Previous Next