1 2 Previous Next 16 Replies Latest reply on Nov 12, 2009 6:53 PM by prati

    Unable to query database - QuerySyntaxException: (object) is not mapped

    asiandub

      hi there,


      (...seam noob...)


      i'm posting the following problem, which i'm fighting with since hours: I am completely unable to run a selection query against my database. I can persists objects without any problems, but as soon as i'm trying to execute a query, i get an exception. So obviously i must be doing something wrong :-(


      this is my scenario:


      i have a user entity bean, which is annotated like this:



      @Entity(name = "user")
      @Table(name = "USERS")
      @Name("user")
      public class User implements Serializable {...




      To persist i execute the following code:



             public void saveTestUser(User user) {
                      userHome.setInstance(user);
                      userHome.persist();
              }



             
      UserHome is more or less empty (just a factory method which i'm not calling right now):
             


      @Name("userHome")
      public class UserHome extends EntityHome<User> {




      Okay, here comes the problem. I'm boiled the code to something which ist just sopposed to retrieve a User from the datebase.



      @Name("userList")
      public class UserList extends EntityQuery<User> {
      
      ...
      
              public int getUserCount() {
                      EntityManager em = getEntityManager();
                      Query query = em.createQuery("select u from User u");
                      List<User> results = query.getResultList();
                      return results.size();
              }
      


             
      And here comes the exception:



      FATAL [application] javax.ejb.EJBTransactionRolledbackException: org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [select u from User u]
      javax.faces.el.EvaluationException: javax.ejb.EJBTransactionRolledbackException: org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [select u from User u]
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
              at javax.faces.component.UICommand.broadcast(UICommand.java:383)
              at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:317)
              at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:292)
              at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:249)
              at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:462)
              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
              at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:154)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:260)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:366)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:493)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
              at java.lang.Thread.run(Thread.java:595)




      (goes on forever, but no new information)


      I have no idea what's going wrong. Been working on the Query-String for hours, there shouldn't be any combination of keywords left i havent't tried yet.


      Help is desperatly needed ;-)


      Cheers from Berlin,
      Jan

        • 1. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
          obfuscator

          What if you use the fully qualified class name? I've had situations where that has helped, not sure why thought. Also, does the hibernate scanner indicate any problems?

          • 2. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
            asiandub

            OH MY GOD


            I used the fully qualified name and it just worked.


            thanks a million :-)


            but - what is the hibernate scanner? neither i nor google have heard about - can you elaborate / provide a link?


            thanks again,


            jan

            • 3. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
              obfuscator

              Glad that I could help!


              About scanner, I just meant that hibernate might complain during startup (scanning your files for annotations) about something not being quite right. I think using a fully qualified class name identifies the class irrespective of its name, ant that is why it worked, but I am not quite sure.


              And oh, I just spotted something, maybe you should change
              @Entity(name = "user") to
              @Entity(name = "User") with capital U?

              • 4. Re: Unable to query database - QuerySyntaxException: (object) is not mapped

                Right, or just get rid of


                (name = "user")



                George

                • 5. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                  asiandub

                  Actually this is a leftover from my debugging efforts. In my understanding,



                  @Entity
                  @Table(name = "USERS")
                  public class User...
                  



                  should be perfectly fine. Or am I missing something? Specially the Query is referencing the class name, isn't it?


                  Where would


                  @Entity(name="somethingFunny")



                  become useful?


                  Cheers,
                  Jan

                  • 6. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                    cjalmeida


                    Where would

                    @Entity(name="somethingFunny")

                    become useful?

                    To differentiate between com.mycompany.people.Supervisor (a person holding a Supervisor job) and com.mycompany.sysadmin.Supervisor (a system monitoring the network's health)?

                    • 7. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                      asiandub

                      well, in my understanding (which can be wrong), i do refer to the classname:



                      Query query = em.createQuery("select u from com.mypackage.user.admin.User u");



                      Query query = em.createQuery("select u from com.myotherpackage.User u");
                      



                      these two would be two different entity beans, referenced by their qualified name. i dont see any place (so far) where i would want to use the name attribute of @Entity?


                      Is this correct?


                      Jan

                      • 8. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                        asiandub

                        new results and conclusion:


                        i was wrong. a query reference defaults against the name of the entity. which by itself defaults against the classname.


                        unless you use


                        @Entity(name = "xyz")




                        in the moment i removed the name-attribute the original query (...User...) started working like a charm.


                        lesson learned: dont use the name attribute of @Entity - unless you have a good reason


                        :-)

                        • 9. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                          waltc

                          Hi, I am having the exact same problem. What did you mean by fully qualified class name? I've been trying to stand up my first, rather simplistic CRUD application using seam. I have found it extremely finicky/sensitive/fragile/whatever. Sometimes things work other times the not and it's just how seam-gen did things or I restarted jboss and it worked.


                          In fact, on this very issue I originall told it to use ear rather than war and everything almost worked. I the changed it to war and started getting this error. I switched back to ear and it worked again. Eventually I played around with it enough and it worked the same with war. But, again, the source is completely generated from the generate step in seam-gen. Where should I add the fully qualified class name?


                          Thanks,


                          Walt

                          • 10. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                            waltc

                            Here is my class



                            /**
                            * Reservations generated by hbm2java
                            */
                            @Entity
                            @Table(name = "reservations", catalog = "ServerReservations")
                            public class Reservations implements java.io.Serializable {

                                 private Integer id;
                                 private Users users;
                                 private Servers servers;
                                 private Date fromDate;
                                 private Date toDate;

                                 public Reservations() {
                                 }

                                 public Reservations(Users users, Servers servers, Date fromDate, Date toDate) {
                                      this.users = users;
                                      this.servers = servers;
                                      this.fromDate = fromDate;
                                      this.toDate = toDate;
                                 }

                                 @Id
                                 @GeneratedValue(strategy = IDENTITY)
                                 @Column(name = "id", unique = true, nullable = false)
                                 public Integer getId() {
                                      return this.id;
                                 }

                                 public void setId(Integer id) {
                                      this.id = id;
                                 }
                                 @ManyToOne(fetch = FetchType.LAZY)
                                 @JoinColumn(name = "user", nullable = false)
                                 @NotNull
                                 public Users getUsers() {
                                      return this.users;
                                 }

                                 public void setUsers(Users users) {
                                      this.users = users;
                                 }
                                 @ManyToOne(fetch = FetchType.LAZY)
                                 @JoinColumn(name = "server", nullable = false)
                                 @NotNull
                                 public Servers getServers() {
                                      return this.servers;
                                 }

                                 public void setServers(Servers servers) {
                                      this.servers = servers;
                                 }
                                 @Temporal(TemporalType.TIMESTAMP)
                                 @Column(name = "fromDate", nullable = false, length = 19)
                                 @NotNull
                                 public Date getFromDate() {
                                      return this.fromDate;
                                 }

                                 public void setFromDate(Date fromDate) {
                                      this.fromDate = fromDate;
                                 }
                                 @Temporal(TemporalType.TIMESTAMP)
                                 @Column(name = "toDate", nullable = false, length = 19)
                                 @NotNull
                                 public Date getToDate() {
                                      return this.toDate;
                                 }

                                 public void setToDate(Date toDate) {
                                      this.toDate = toDate;
                                 }

                            }

                            • 11. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                              waltc
                              Sorry, that didn't work well...


                              /**
                              * Reservations generated by hbm2java
                              */
                              @Entity
                              @Table(name = "reservations", catalog = "ServerReservations")
                              public class Reservations implements java.io.Serializable {

                                   private Integer id;
                                   private Users users;
                                   private Servers servers;
                                   private Date fromDate;
                                   private Date toDate;

                                   public Reservations() {
                                   }

                                   public Reservations(Users users, Servers servers, Date fromDate, Date toDate) {
                                        this.users = users;
                                        this.servers = servers;
                                        this.fromDate = fromDate;
                                        this.toDate = toDate;
                                   }

                                   @Id
                                   @GeneratedValue(strategy = IDENTITY)
                                   @Column(name = "id", unique = true, nullable = false)
                                   public Integer getId() {
                                        return this.id;
                                   }

                                   public void setId(Integer id) {
                                        this.id = id;
                                   }
                                   @ManyToOne(fetch = FetchType.LAZY)
                                   @JoinColumn(name = "user", nullable = false)
                                   @NotNull
                                   public Users getUsers() {
                                        return this.users;
                                   }

                                   public void setUsers(Users users) {
                                        this.users = users;
                                   }
                                   @ManyToOne(fetch = FetchType.LAZY)
                                   @JoinColumn(name = "server", nullable = false)
                                   @NotNull
                                   public Servers getServers() {
                                        return this.servers;
                                   }

                                   public void setServers(Servers servers) {
                                        this.servers = servers;
                                   }
                                   @Temporal(TemporalType.TIMESTAMP)
                                   @Column(name = "fromDate", nullable = false, length = 19)
                                   @NotNull
                                   public Date getFromDate() {
                                        return this.fromDate;
                                   }

                                   public void setFromDate(Date fromDate) {
                                        this.fromDate = fromDate;
                                   }
                                   @Temporal(TemporalType.TIMESTAMP)
                                   @Column(name = "toDate", nullable = false, length = 19)
                                   @NotNull
                                   public Date getToDate() {
                                        return this.toDate;
                                   }

                                   public void setToDate(Date toDate) {
                                        this.toDate = toDate;
                                   }

                              }
                              |``

                              • 12. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                                asiandub

                                hey walt,


                                the class looks okay.


                                As you wrote that you have exactly the same problem as i had back in august, i assume that you are working in ejbql in Home / List - classes? Please post your exception.


                                Concerning your 'seam is fragile' impression: i cannot (and will not) deny that. ;-) I think this is the back side of the 'convention over configuration' pradigm - everything seems to be smooth and mellow on a first glance, but as soon as the first problems / change-requests / bugs appear, you have to understand the hidden parameters and defaults. at the end of the day this is JEE. And JEE is  not exactly known as a simple framework..


                                same goes for your WAR / EAR switch. a simple question in seam-gen, but a huuuge difference in your infrastructure. in the EAR-scenario you are using the complete JEE-application server stack, in the WAR-scenario you have a light-weight servlet container and seam for the rest.


                                ...


                                looking forward to help you out with your problem,


                                cheers,
                                jan

                                • 13. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                                  waltc
                                  Hi Jan,
                                     I appreciate your help. I've been in Java-land for 7-8 years now and have avoided jsp and J2EE like the plague. Well, no, put differently, I've avoided HTML like the plague. JSP's just creeped me out and doing tables within tables just made my head hurt, not to mention the resulting file appearance. I kind of equated the whole thing to writing Windows GUIs without an IDE. Yes, it can be done but why would one want to. I figured sooner or later someone would come up with a WYSIWYG environment for page construction and app generation. Yet I was always VERY envious of those that wrote web apps, in fact, I was always a huge opponent to the whole thin client movement yet now, with Ajax, it hard to fight that trend. I've done a couple of JSF apps in Tomcat and was pretty impressed. Nothing that would bump against the everything is a post issue(s). When I ran across mentions of Seam I decided to jump in.  Here is my original issue
                                  http://www.seamframework.org/Community/PersistenceException#comment57493

                                  It turns out that problem was, ODDLY, the use of from in the table. The error, however, was the construction of the update, which is now working for some unknown but highly appreciated, reason. The issue was the where clause was never getting constructed. When I changed the column names it properly added where id=1 and started droping columns that hadn't changed. I view that as a Hibernate issue, not a Seam issue and certainly not a JBOSS 5 issue. Of course I could be wrong, I am, after all, the new guy here.

                                  In a nutshell. the issue I am trying to solve is this. There is a collection of servers, servers have a description, nic(s), OS, etc. Some servers have multiple NICs so there is a many-to-one between the server and the ipaddress table. One, or more, ipaddress rows will point to the same server. A server can be reserved by a user. Some development/testing does not lend itself to sharing. A reservation is for a certain period of time (from and to) and for a given user. So the user is simply a name and id. There can be but one active reservation for any given machine at a time. Once the reservation expires the entry is copied to an archive and the reservation is deleted. A server with an active reservation can not be reserved.

                                  I could have sworn the hbm2ddl took a none parameter. I have found hibernate adding duplicate foreign key clauses and dropping them as well. Right now the server list does not depict the ip address(es).  But when I switched back to ear and rebuilt the world from scratch that appears to be my only issue. Once I get past these problems I want an output like like:

                                  name           description     OS   Processor(s) type memory IP Address(s)    status        action   

                                  cor720           Dell XPS 720  Linux  4          2.4Ghz  3GB  192.168.0.3     reserved       cancel
                                                                                                192.168.0.4

                                  cor7201          Dell XPS 720  Linux  4          2.4Ghz  8GB  192.168.0.5     available       reserve
                                                                                                192.168.0.6

                                  I was hoping I could knock this off in a day or two. So far that hasn't proven to be the case.

                                  Walt
                                  • 14. Re: Unable to query database - QuerySyntaxException: (object) is not mapped
                                    asiandub

                                    hi walt,


                                    well, the first line of this thread classifies my level of knowledge about seam. i improved over the last months, but at the end of the day i'm still pretty new to seam, specially if it comes to any detailed question about distribution versions and configuration issues.


                                    what i can say comes in two parts: first: your problem / exercise looks interesting and it is certainly a good start with seam. 1-2 two days sounds okay, assuming you got your infrastructure set up and your seam / jee-knowledge is profound. just add x extra-days per not-fulfilled issue ;-)


                                    second (and seriously): seam seams technologies together. most of these (like JSF, hibernate, JPA, ...) are of a inherent complexity, and hundreds of books have been written about them.


                                    so, in my opinion, there is noway to avoid this complexity at all, whether you are using seam or not. furthermore, seam adds another level of complexity (well hidden sometimes, but always existing), which has to be mastered ontop.


                                    this doesn't make live easier, for obvious reasons ;-)


                                    anyhow - seam is pretty cool stuff. just make sure that you advance step by step, and at the end of the day, you'll get a web-app with a lot less pain than with the 'raw' technologies.


                                    not much of a help for your concrete problem, but if you post your concrete issues, i'm sure the community will give it's best to help you out.


                                    cheers from berlin / germany,
                                    jan





                                    1 2 Previous Next