You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 28 Members of 4060 |
| Forum: Seam Users |
06. Aug 2008, 14:44 CET | Link |
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
8 Replies: | |||
|---|---|---|---|
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? |
|||
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 |
|||
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? |
|||
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 |
|||
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)? |
|||
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 |
|||
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 :-) |
.