-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Problems when getting items from the DB
PostPosted: Fri Sep 30, 2005 4:12 pm 
Newbie

Joined: Thu Jun 09, 2005 9:07 am
Posts: 13
Hi,

I'm able to insert and update items into the database but when I try to get a list of object from the DB, I get an error and it has little meaning to me but I did put some flags to know where it crashed exactly.

The message is:
javax.servlet.jsp.JspException: Exception creating bean of class PandoraForm: {1}
org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:563)
org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)


It prints pass and pass1 but none others in this method:
public static List execRequeteMaison(String requete)
throws HibernateException{
if (requete == null){
return new ArrayList();
}
Session session = currentSession();
Transaction tx = session.beginTransaction();
System.out.println("pass");
Query query = session.createQuery(requete);
System.out.println("pass1");
List result = query.list();
System.out.println("pass2");

tx.commit();
System.out.println("pass3");

session.close();
System.out.println("passe4");

return result;
}

And it's called from this constructor:
public PandoraForm () {
List reqs = HibernateManager.execRequeteMaison("FROM requetes");
}


I tried with a full query SELECT * FROM requetes but I get the same problem. There are 2 items in the DB in case it matters.

Any idea where the problem is?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 5:03 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
This is hard to debug without the stack trace.

Do a try catch around your code and print the stack trace of the error and of its cause (e.getCause().printstackTrace()). Usually, Hibernate gives you more information than what you are getting. It should inform you about query translation problems or database errors.

Apparently, the error comes from the translation or execution of the query (which happens when you do list()).

Question: 'requetes' is the name of your java entity or of your database table?

PS - Hibernate forum works with credits. I have answered one of your questions yesterday, but you have not followed up and rated my answers. I would appreciate if you could do so. http://forum.hibernate.org/viewtopic.php?t=948223

Vincent.

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 5:12 pm 
Newbie

Joined: Thu Jun 09, 2005 9:07 am
Posts: 13
vgiguere wrote:
This is hard to debug without the stack trace.

Do a try catch around your code and print the stack trace of the error and of its cause (e.getCause().printstackTrace()). Usually, Hibernate gives you more information than what you are getting. It should inform you about query translation problems or database errors.

Apparently, the error comes from the translation or execution of the query (which happens when you do list()).

Question: 'requetes' is the name of your java entity or of your database table?

PS - Hibernate forum works with credits. I have answered one of your questions yesterday, but you have not followed up and rated my answers. I would appreciate if you could do so. http://forum.hibernate.org/viewtopic.php?t=948223

Vincent.


I will try that.

The entity is named Requete while the table is named requetes. So, if I understand well how it should work, I sould get a List of Requete's castable objects. My method that save a Requete object into the DB works fine so the Requete.hbm.xml shoulc be ok but I'll see what the try/catch message will give.

Technicaly speaking, I answered my own question but you and christian were both very helpful so I gave both of you credits. I didn't know about this credit thing, sorry.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 5:25 pm 
Newbie

Joined: Thu Jun 09, 2005 9:07 am
Posts: 13
Now that's strange, it tells me that requetes is not mapped....but I can save and saveOrUpdate a requete object into the requetes table without trouble. I'm confused here, any idea what's wrong?

here's the whole stack message:

requetes is not mapped.
at org.hibernate.hql.ast.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:85)
at org.hibernate.hql.ast.FromElementFactory.addFromElement(FromElementFactory.java:77)
at org.hibernate.hql.ast.FromClause.addFromElement(FromClause.java:67)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:217)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2830)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at HibernateManagement.HibernateManager.execRequeteMaison(HibernateManager.java:93)
at PandoraForm.<init>(PandoraForm.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at java.lang.Class.newInstance0(Class.java:350)
at java.lang.Class.newInstance(Class.java:303)
at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:231)
at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:837)
at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:552)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
at org.apache.jsp.pages.Pandora_jsp._jspx_meth_html_form_0(org.apache.jsp.pages.Pandora_jsp:192)
at org.apache.jsp.pages.Pandora_jsp._jspx_meth_html_html_0(org.apache.jsp.pages.Pandora_jsp:135)
at org.apache.jsp.pages.Pandora_jsp._jspService(org.apache.jsp.pages.Pandora_jsp:95)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 5:34 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
Yeah, that's what I thought. You request needs to be issued on the name of the Entity, rather than on the name of the table.


You code should be:
List reqs = HibernateManager.execRequeteMaison("FROM " + Requetes.class.getName());

That will solve the problem.

Let me know if it works for you :)

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 5:55 pm 
Newbie

Joined: Thu Jun 09, 2005 9:07 am
Posts: 13
vgiguere wrote:
Yeah, that's what I thought. You request needs to be issued on the name of the Entity, rather than on the name of the table.


You code should be:
List reqs = HibernateManager.execRequeteMaison("FROM " + Requetes.class.getName());

That will solve the problem.

Let me know if it works for you :)


It worked but...I don't understand and I wonder if you could light the bulb over my head with an explanation please? What the class name has to do with the table name in a SELECT? Btw, the entity name is Requete, the table name is requetes so I used Requete.class.getName()

In the doc about createQuery, the straight table name was used.

in my Requete.hbm.xml, the class tag is <class name="HibernateManagement.Requete" table="requetes">

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 10:43 am 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
The idea of mapping your queries on your entities and not on your table names is to provide a layer of abstraction over your physical model.

Also, you are right, You do not have to do:

Code:
List reqs = HibernateManager.execRequeteMaison("FROM" + Requete.class.getName());


It would work with Requête only:
Code:
List reqs = HibernateManager.execRequeteMaison("FROM Requete");


It was more to make a point that the entity is what matters, not the table name. Also, the package name would only become important if you would map several entities with the same class name but in different packages.

As far as the documentation goes, knowing now the answer, re-read the example. You will see that they always map their queries to the entities, and not to the table name (If you find an error, post it)

Hope this answers your questions.

Have a nice day,

Vincent.

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.