1 2 Previous Next 20 Replies Latest reply on Sep 11, 2010 4:33 AM by danwin

    NamedQuery problem: TABLE is not mapped

    pi4630

      Hi,

      I'm using a NamedQuery in my Artikel entity bean, but mapping by annotation doesn't take place.
      The bean starts like this:

      @Entity
      @Table(name="ARTIKEL")
      @NamedQuery(name="findAllArtikel", query ="SELECT a FROM ARTIKEL a ORDER BY a.artnr")
      public class Artikel implements java.io.Serializable {
      


      When I start up my JBoss, I get the follwoing exception:

      ERROR [SessionFactoryImpl] Error in named query: findAllArtikel
      org.hibernate.hql.ast.QuerySyntaxException: ARTIKEL is not mapped [SELECT a FROM ARTIKEL a ORDER BY a.artnr]
      


      My persistence.xml looks like this
      <?xml version="1.0" encoding="UTF-8"?>
      <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_1_0.xsd"
       version="1.0">
       <persistence-unit name="JavaEE">
       <jta-data-source>java:DefaultDS</jta-data-source>
       <properties>
       <property name="hibernate.archive.autodetection" value="class"/>
       </properties>
       </persistence-unit>
      </persistence>
      

      Originally, the persistence.xml was without the properites section, a thing I ran into looking around in Java forums. I am using HSQL db. There's obviously something missing fro hibernate, but I can't say what to put where.

      I am using Java SDK 1.5 along with Jboss 4.0.4 GA.


        • 1. Re: NamedQuery problem: TABLE is not mapped
          wolfgangknauf

          Hi,

          in your named query, you have to use the name of the entity bean class, not the table name.
          So it should be "SELECT a FROM Artikel a ORDER BY a.Artnr".

          If the property has getter/setter "getArtnr"/"setArtnr", it has to be named "Artnr" in the query.

          Hope this helps

          Wolfgang

          • 2. Re: NamedQuery problem: TABLE is not mapped
            pi4630

            Wolfgang, thanks for caring, thumbs up! The book I'm studying does not mention case sensitivity, and I thought the statement would be table related, not class related.

            So thank you very much, because after changing the case, it worked.

            There's one thing: I have indeed a artnr field and public getters and settes which render it Artnr (getArtnr and setArtnr). I tried your hint first, i.e.

            SELECT a FROM Artikel a ORDER BY a.Artnr
            but this yields an exception when deploying:
            ERROR [SessionFactoryImpl] Error in named query: findAllArtikel
            org.hibernate.QueryException: could not resolve property: Artnr of: ser.kap08.Artikel [SELECT a FROM ser.kap08.Artikel a ORDER BY a.Artnr]

            If I try with the field case instead, i.e.
            SELECT a FROM ser.kap08.Artikel a ORDER BY a.artnr

            it's fine.



            • 3. Re: NamedQuery problem: TABLE is not mapped
              wolfgangknauf

              I'm sorry, I was wrong with the casing of the property. You are right, it has to be lower case.

              Getter/Setter "getArtnr"/"setArtnr" indeed form a property "artnr".

              Wolfgang

              • 4. Re: NamedQuery problem: TABLE is not mapped
                pi4630

                Thank *you* :)!

                • 5. Re: NamedQuery problem: TABLE is not mapped
                  danwin

                  I am getting the "TABLE is not mapped" exception when I don't map the table explicitily in my persistence.xml. Obviously the autodetection property doesn't work.

                   

                  <?xml version="1.0" encoding="UTF-8"?>
                  <persistence version="1.0"
                      xmlns="http://java.sun.com/xml/ns/persistence">
                      <persistence-unit name="Employee-Details"> 
                  
                  
                           <jta-data-source>java:/jdbc/employee</jta-data-source>
                  
                   
                  
                           <properties> 
                  
                   
                  
                               <!-- for detecting the Mapped Files -->
                              <property name="hibernate.archive.autodetection" value="class" />
                              
                              <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
                              <property name="hibernate.show_sql" value="true" />
                              <property name="hibernate.format_sql" value="true" />             
                  
                  
                  
                           </properties>
                      </persistence-unit>
                  </persistence>
                  

                   

                  When I add <class>employee.EmployeeEntity</class> I don't have any problem.

                  But I would like to generate the tables and entities. And therefore I don't want to add configuration everytime.

                   

                  Can anyone help?

                  • 6. Re: NamedQuery problem: TABLE is not mapped
                    wolfgangknauf

                    Hi David,

                     

                    let's continue this in a new thread, as it might not be related to the original question.

                     

                    Actually, I don't get the problem ;-). So you have autogenerated classes, which contain no annotations, but you want to let the server detect them as EJBs?

                    I think a hibernate property will not help, you need to do an EJB way. If annotations are not possible, declare them in ejb-jar.xml.

                     

                    Hope this helps

                     

                    Wolfgang

                    • 7. Re: NamedQuery problem: TABLE is not mapped
                      danwin

                      Sorry for the confusing loop. At my current project I don't generate code but I get the "TABLE is not mapped" message if I don't add the line

                       

                      <class>employee.EmployeeEntity</class>

                       

                      to my persistence.xml.

                       

                      My question is, why the table don't get mapped although I use annotations

                       

                      package employee;
                      
                      import javax.persistence.Entity;
                      import javax.persistence.Id;
                      import javax.persistence.Table;
                      
                      @Entity
                      @Table(name = "employee")
                      public class EmployeeEntity {
                          @Id
                          private int empNo;
                          private String empName;
                          private String ibu;
                          private String designation;
                      

                       

                      and autodetection:

                       

                      <property name="hibernate.archive.autodetection" value="class" />
                      

                       

                      ???

                       

                      Thanks,

                      Daniel

                      • 8. Re: NamedQuery problem: TABLE is not mapped
                        jaikiran

                        Looking at the hibernate code which parses this configuration, I think there might be a bug in there. I'm not completely sure because I just quickly glanced over the code without going into too much details. Can you quickly try this:

                         

                        <property name="hibernate.archive.autodetection" value="class,hbm" />

                         

                         

                        or even this:

                         

                        <property name="hibernate.archive.autodetection" value="class," />

                         

                        (Note the "," after "class")

                         

                        Let us know how it goes.

                        • 9. Re: NamedQuery problem: TABLE is not mapped
                          danwin

                          I've tried both, but I still get:

                           

                          10:25:16,819 INFO  [STDOUT] org.hibernate.hql.ast.QuerySyntaxException: EmployeeEntity is not mapped [select e from EmployeeEntity e]
                          
                          • 10. Re: NamedQuery problem: TABLE is not mapped
                            wolfgangknauf

                            Hi Daniel,

                             

                            actually, it should not be necessary to trouble with hibernate config, it should detect Entity Beans itself.

                             

                            Where do you declare and use your query? I don't see a "@NamedQuery" annotation on the entity (where they have to be placed, other locations as session beans don't work as far as I remember). Do you call the query directly against the entity manager?

                             

                            Best regards

                             

                            Wolfgang

                            • 11. Re: NamedQuery problem: TABLE is not mapped
                              danwin

                              Hello Wolfgang,

                               

                              yes I am using an EntityManager instance to create a query:

                               

                              EntityManagerFactory emf = Persistence.createEntityManagerFactory("Employee-Details");
                              em = emf.createEntityManager();
                              EntityTransaction et = em.getTransaction();
                              et.begin();
                              Query query = em.createQuery("select e from EmployeeEntity e");
                              empList = query.getResultList();
                              

                               

                              Does it make a difference to use the @NamedQuery annotation?

                               

                              Kind regards,

                              Daniel

                              • 12. Re: NamedQuery problem: TABLE is not mapped
                                wolfgangknauf

                                Hi,

                                 

                                basically, your code should work I think.

                                 

                                I have one question left: where is your code? Is it in a web app? Or in a session bean in the EJB jar? Or in an application client?

                                I assume that you did not place the code fragment in the EJB jar file, and maybe this is the reason why the entity name cannot be resolved.

                                 

                                Best regards

                                 

                                Wolfgang

                                • 13. Re: NamedQuery problem: TABLE is not mapped
                                  danwin

                                  Hi Wolfgang,

                                   

                                  I am deploying a war file ..

                                   

                                  src

                                  employee

                                  EmployeeBean.java

                                  EmployeeEntity.java

                                  EmployeeService.java

                                  META-INF

                                  persistence.xml

                                  WebContent

                                  META-INF (contains only empty MANIFEST)

                                  WEB-INF

                                  lib (some jars)

                                  faces-config.xml

                                  web.xml

                                  EmployeeHome.jsp

                                  Home.jsp

                                   

                                   

                                   

                                  Daniel

                                  • 14. Re: NamedQuery problem: TABLE is not mapped
                                    wolfgangknauf

                                    So you have a JavaEE6 project? In previous versions, Entities in a web module were not possible, they are a new feature of JavaEE6. Maybe there is a problem with hibernate handling them.

                                     

                                    Best regards

                                     

                                    Wolfgang

                                    1 2 Previous Next