检查一下 session.createQuery(sql)中的sql语句有没有写对啊。

解决方案 »

  1.   

    我写了是这样的Query query =session.createQuery(
                                    "select Vipdata from com.xiebing.hibernate.Vipdata Vipdata order by Vipdata.vipname");
      

  2.   

    在MyEclipse中连接数据库没有问题啊,我是用database Explorer链接的不知道这样合理不
      

  3.   

    我还有哪些方面也许不正确?我花了两天的时间来,结果是什么都看不见,郁闷ing
      

  4.   

    com.xiebing.hibernate.Vipdata Vipdata
    这个别名不对,跟原名是一样的
      

  5.   

    "from Vipdata as vipdata order by vipdate.vipname"
      

  6.   

    楼上的几位大哥;我照你们说的做了还是不行,异常:
    message description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: net.sf.hibernate.exception.SQLGrammarException: Could not execute query
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause java.lang.RuntimeException: net.sf.hibernate.exception.SQLGrammarException: Could not execute query
    com.xiebing.hibernate.VipService.getVipdataList(VipService.java:101)
    org.apache.jsp.AddVipData_jsp._jspService(org.apache.jsp.AddVipData_jsp:134)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:325)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:245)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.4 logs.
      

  7.   

    我的原文件:
    import java.util.List;import net.sf.hibernate.HibernateException;import net.sf.hibernate.ObjectNotFoundException;import net.sf.hibernate.Query;import net.sf.hibernate.Session;import com.xiebing.hibernate.Vipdata;
    /**
     * @author Administrator
     *
     * TODO 要更改此生成的类型注释的模板,请转至
     * 窗口 - 首选项 - Java - 代码样式 - 代码模板
     */
    public class VipService {

        private static VipService instance = null;    private VipService()    {    }    /**     * 得到VipService的单态实例     * @return <code>VipService</code> singleton.     */    public static synchronized VipService getInstance()    {           if (instance == null)           {                  instance = new VipService();           }           return instance;    }
        /**     * 得到所有的记录      *      * @return 记录的列表     */    public List getVipdataList()    {           Session session = null;           try           {                  session = SessionFactory.currentSession();                  //创建一条HQL查询                  Query query =                         session.createQuery(                                "select Vipdata from com.xiebing.hibernate.Vipdata Vipdata order by Vipdata.vipname");                  return query.list();//           }           catch (HibernateException e)           {                  System.err.println("Hibernate Exception" + e.getMessage());                  throw new RuntimeException(e);           }           finally           {                  if (session != null)                  {                         try                         {                                session.close();                         }                         catch (HibernateException e)                         {                                System.err.println("Hibernate Exception" + e.getMessage());                                throw new RuntimeException(e);                         }                  }           }    }
    }
      

  8.   

    我的配置:
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
              "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
              "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd"><!-- DO NOT EDIT: This is a generated file that is synchronized -->
    <!-- by MyEclipse Hibernate tool integration.                   -->
    <hibernate-configuration>    <session-factory>
            <!-- properties -->         
            <property name="connection.username">sa</property>
            <property name="connection.url">jdbc:odbc:t</property>
            <property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
            <property name="connection.password">123</property>
            <property name="connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>             <!-- mapping files -->
            <mapping resource="com/xiebing/hibernate/Vipdata.hbm.xml"/>    </session-factory></hibernate-configuration>
      

  9.   

    欢迎加入QQ群14673042 .j2EE developer