Problem with Hibernate+Mysql VIEW

All greetings!

MySQL VIEW structure:

CREATE VIEW `view_rating` AS select `rating`.`id` AS `id`,`rating`.`last_update` AS `last_update`,`casinos`.`name` AS `casino`,`parameters`.`name` AS `parameter`,`rating`.`value` AS `value`,`parameters`.`percent` AS `percent`,((`rating`.`value` / 100) * `parameters`.`percent`) AS `rating_value` from ((`casinos` join `parameters`) join `rating`) where ((`rating`.`casino_id` = `casinos`.`id`) and (`rating`.`parameter_id` = `parameters`.`id`));


Class Transactions:

import org.hibernate.Query;
import org.hibernate.Session;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

public class Transactions {
    public static String QUERY_ALL_CASINOS="from view_rating ";
...
    Session session;
    private static SessionFactory ourSessionFactory;

    static {
        try {
            ourSessionFactory = new AnnotationConfiguration().
                    configure("hibernate.cfg.xml").
                    buildSessionFactory();
        }
        catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static Session getSession() throws HibernateException {
        return ourSessionFactory.openSession();
    }

    public List executeHQLQuery(String hql) {
        session = getSession();
        List resultList=null;
        try {
            session.beginTransaction();
            Query q = session.createQuery(hql);
            resultList = q.list();
            session.getTransaction().commit();
        } catch (HibernateException he) {
            he.printStackTrace();
        }
        return resultList;
    }
}

JSP Page:

...
<%
            Transactions tr = new Transactions();
            List resultList = tr.executeHQLQuery(tr.QUERY_ALL_CASINOS);
            for(Object o : resultList) {
                out.print("<tr>");
                ViewRating casino = (ViewRating)o;
                out.print("<td>"+casino.getValue()+"</td>");
                out.print("</tr>");
            }
%>

...


Error:


HTTP Status 500 -


type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 22

19:     <td><b>Description</b></td>
20: </tr>
21: <%
22:             Transactions tr = new Transactions();
23:             List resultList = tr.executeHQLQuery(tr.QUERY_ALL_CASINOS);
24:             for(Object o : resultList) {
25:                 out.print("<tr>");


Stacktrace:
     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: Could not initialize class rating.casino.data.Transactions
     org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
     org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
     org.apache.jsp.index_jsp._jspService(index_jsp.java:90)
     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause

java.lang.NoClassDefFoundError: Could not initialize class rating.casino.data.Transactions
     org.apache.jsp.index_jsp._jspService(index_jsp.java:72)
     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.


Apache Tomcat/6.0.20



The file ViewRating.hbm.xml you get an error on the word class with the following contents:

org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".



Please help me to use MySQL VIEW!
Sorry for my English:)

Please sign in to leave a comment.