7 Replies Latest reply on Nov 15, 2007 6:15 AM by itsme

    ERROR: <table name> is not mapped

    umeshgeeta

      Hi,

      I am using JBoss 4.0.3RC1 release with 'default' configuration. My database is MySQL 4.1. version and JDBC driver is "mysql-connector-java-3.1.10". My application is able to use the specified data source.

      The error I get is:

      javax.ejb.EJBException: null; CausedByException is:
      lab_master is not mapped. [from lab_master]
      at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.ja
      va:46)
      at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:70)
      at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java
      :134)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:88)
      at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInt
      erceptor.java:72)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:88)
      at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(Stateles
      sInstanceInterceptor.java:39)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:88)
      at org.jboss.aspects.security.AuthenticationInterceptor.invoke(Authentic
      ationInterceptor.java:63)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:88)
      at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(Asynchrono
      usInterceptor.java:93)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.
      java:88)
      at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessCont
      ainer.java:148)
      at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalPro
      xy.java:65)
      at $Proxy116.getLabs(Unknown Source)

      I have a table created "lab_master" in the "labuse" database or catalog of MySql. My entity bean class is BrcdLab annotated as @Entity and @Table(name="lab_master"). Auto generated integer Id is the key.

      BrcdLabManager is the business interface implemented by a stateless session bean BrcdLanManagerBean where a call to "getLabs()" is implemented. The call simply returns a collection:

      return em.createQuery("from lab_master").getResultList();

      Reference "em" is to a @PersistentContext EntityManager as defined in persistence.xml.

      The questions are:

      - Why do I get "table not mapped" error?
      - Error message is not revealing nor tells what could be done to solve the issue. How do we get more information about what is happening?

      I searched the forum, but could not find any thread discussing "table not mapped" error issue. After loosing more than 2 days of worth, still trying to correct myself. Lack of information is frustrating. Ejb3Trailblazer runs for me and my tiny entity mapping is modelled on that example except the change of using MySQL instead of HYSQL as used in the example.

      Any hints are welcome.

      Thanks,

      Umesh.

        • 1. Re: ERROR: <table name> is not mapped
          umeshgeeta

          Well, it is always good to find answer to your question on your own. Yes, it was my mistake. Here is what happened:

          I have an entity object named BrcdLab mapped to the table lab_master. In another bean where I was making query to get all records of this objects (all labs added in the table corresponding to BrcdLab); my EJB object query was referring to the table name. It was

          "from lab_master l". It should be "from BrcdLab l" i.e. it should be the object in the query rather than the table name. It is satisfying to see that EJB 3.0 specs are consistent - once the trouble of mapping object to table is taken by the container provider; EJB wants us to consistently refer to Object names and not to the table name. That is why there is EJB based Object query language.

          The bigger question is why this error occurred? The problem is in the example EJB3Trail blazer case, both table and object names are same! For example Fund object and Fund table; except for the lower case for the table name. That kind of makes it to miss this point when a beginner like me tries to build a tiny example off that sample. It would help if table and object names are slightly differentiated by some prefix or suffix. It is understandable that EJB3.0 wants developer to think table and object synonymously; but it leads to problem at times while implementation.

          Hopefully, anyone visiting to this forum and facing this problem would find this explanation useful.


          Thanks,

          Umesh.

          • 2. Re: ERROR: <table name> is not mapped
            billathome


            I had the same error and i am using the name of the object
            instead the name of the table.

            I can´t know what is going wrong.

            • 3. Re: ERROR: <table name> is not mapped
              epbernard

              your entity is not part of your persistence unit

              • 4. Re: ERROR: <table name> is not mapped
                andreyon

                10x a lot!

                • 5. Re: ERROR: <table name> is not mapped
                  da.ogre

                  thank you, umeshgeeta!
                  I had the same problem and your explanation was the solution.

                  • 6. Re: ERROR: <table name> is not mapped
                    manitito

                    Table name and Class name Users

                    List list = session.createQuery("SELECT * FROM USERS).list();
                    Use HQL -> exception


                    List list = session.createSQLQuery("SELECT * FROM USERS).list();
                    Pure SQL -> work, with out problem

                    • 7. Re: ERROR: <table name> is not mapped
                      itsme

                      How is your class' name. Suppose it is

                      x.y.User

                      the your HQL-Code would look like
                      SELECT u FROM User u


                      \sandor\