I have a simple application using a jsp to presenting information. It works through Hibernate to a MySQL database. I am using Eclipse 3.1.1, MyEclipse workbench 4.1 MySQL 5.0, and Hibernate 3.0 The application is running on JBoss4.0.3SP1 This error is taking place when I take the results and try to place it in the session.
What I want to know is retreiving the information from the database looks as though I am dealing with objects and not a collection of Catalog.class. When I go look at the current version of Hibernate 3.1, I can see several overloaded methods for createSQLQuery, yet I can not find them when I try to use them in my code. The only method avaialble to me is the one method with a String as a parameter for the SQL query. I would assume this is because of MyEclipse only using Hibernate3.0 and not Hibernate 3.1.
How does one ensure Hibernate3.0 returns a collection of Catalog classes in the collection?
In the JSP I am calling:
AddJournal.jsp
Code:
List catalogList = CatalogService.getInstance().getCatalogList();
request.setAttribute("catalog", catalogList); <<< exception is happening here.....
Hibernate version: 3.0
Mapping documents:Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.rrcorp.hibernate.Catalog" table="catalog">
<id name="catalogId" type="integer">
<column name="CatalogId" />
<generator class="native"></generator>
</id>
<property name="journal" type="string">
<column name="Journal" length="25" />
</property>
<property name="publisher" type="string">
<column name="Publisher" length="25" />
</property>
<property name="date" type="string">
<column name="Date" length="25" />
</property>
<property name="title" type="string">
<column name="Title" length="45" />
</property>
<property name="author" type="string">
<column name="Author" length="25" />
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():CatalogServiceCode:
public List getCatalogList(){
Session session = null;
try{
session = SessionFactory.currentSession();
// use lower case names for attritbutes and
// substitute for table name
String SQL_QUERY ="SELECT c.catalogId,c.journal,c.publisher," +
"c.date,c.title,c.author FROM Catalog c";
Query query = session.createQuery(SQL_QUERY);
for(Iterator it=query.iterate();it.hasNext();){
Object[] row = (Object[]) it.next();
System.out.println("CatalogId: " + row[0]);
System.out.println("Journal: " + row[0]);
System.out.println("Publisher: " + row[1]);
System.out.println("Date: " + row[2]);
System.out.println("Title: " + row[3]);
System.out.println("Author: " + row[4]);
}//end for loop
query.setMaxResults(10);
return query.list();
}catch (ObjectNotFoundException onfe){
return null;
}finally {
if(session != null){
try{
session.close();
}catch (HibernateException e){
System.err.println("Hibernate Exception: "+ e.getMessage());
throw new RuntimeException(e);
}
}
}
}//end method
Full stack trace of any exception that occurs:Code:
[09:17:33,828] [ERROR] [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.ClassCastException: [Ljava.lang.Object;
at org.apache.jsp.AddJournal_jsp._jspService(org.apache.jsp.AddJournal_jsp:150)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
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.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
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.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
Name and version of the database you are using:Code:
MySQL 5.0