gpt4 book ai didi

mysql - Hibernate错误-org.hibernate.hql.internal.ast.QuerySyntaxException

转载 作者:行者123 更新时间:2023-11-30 23:05:43 26 4
gpt4 key购买 nike

我正在尝试检索管理员输入的学生详细信息(即显示到学生页面)。但是这样做,我遇到了一个错误

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

119: sessionn.beginTransaction();
120: String enroll=Stu_Name.getEnroll();
121: out.println(enroll);
122: Query query=sessionn.createQuery("from StuAcadDetails where ENROLLMENT_NUMBER="+enroll );
123: List<StuAcadDetails> detail=(List<StuAcadDetails>)query.list();
124:
125: for(StuAcadDetails stuDetails:detail)


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
root cause

org.hibernate.hql.internal.ast.QuerySyntaxException: StuAcadDetails is not mapped [from StuAcadDetails where ENROLLMENT_NUMBER=NU/A9/45055]
org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180)
org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93)
org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:324)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3420)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3309)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:250)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:105)
org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:222)
org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:200)
org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1703)
org.apache.jsp.StuGenInfo_005fStu_jsp._jspService(StuGenInfo_005fStu_jsp.java:203)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.

Apache Tomcat/7.0.47

在我的项目中,管理员输入了学生的学术信息,学生获得了登录 ID,这是一个名为 Enrollment_Number 的主键。一旦学生登录,学生应该能够看到有关其学术的所有信息。

我试图通过将注册保存到 session 中(保存在登录页面中)并使用此注册(在 StuGenInfo_Stu.jsp 页面中检索注册)从 MySql 数据库中获取相应的记录来实现这一点。
配置文件

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>

<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/MBSIS</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<mapping class="org.faculty.entity.RegistrationFaculty"/>
<mapping class="org.faculty.entity.StuAcadDetails"/>
</session-factory>
</hibernate-configuration>

StuAcadDetails

@Table(name="ACADEMICS_DETAILS")
@Entity
public class StuAcadDetails {

@Id
@Column(name="ENROLLMENT_NUMBER")
private String enroll;

@Column(name="SEMESTER")
private int semester;

@Column(name="BRANCH")
private String branch;

@Temporal(TemporalType.DATE)
@Column(name="DATE_OF_JOINING")
private Date doj;

@Column(name="ATTDCE_IN_THEORY")
private int attThry;

@Column(name="ATTDCE_IN_PRACTICAL")
private int attPrac;

@Column(name="PREVIOUS_SEM_PERCENTAGE")
private float preSemPer;

@Column(name="OVERALL_AGGREGATE")
private float overallAggr;

@Column(name="SESSIONAL_PERCENTAGE")
private float sessPer;

@Column(name="PERFORMANCE")
private String performance;

/*********************************************************************/
public String getEnroll() {
return enroll;
}
public void setEnroll(String enroll) {
this.enroll = enroll;
}
public int getSemester() {
return semester;
}
public void setSemester(int semester) {
this.semester = semester;
}
public String getBranch() {
return branch;
}
public void setBranch(String branch) {
this.branch = branch;
}
public Date getDoj() {
return doj;
}
public void setDoj(Date doj) {
this.doj = doj;
}
public int getAttThry() {
return attThry;
}
public void setAttThry(int attThry) {
this.attThry = attThry;
}
public int getAttPrac() {
return attPrac;
}
public void setAttPrac(int attPrac) {
this.attPrac = attPrac;
}
public float getPreSemPer() {
return preSemPer;
}
public void setPreSemPer(float preSemPer) {
this.preSemPer = preSemPer;
}
public float getOverallAggr() {
return overallAggr;
}
public void setOverallAggr(float overallAggr) {
this.overallAggr = overallAggr;
}
public float getSessPer() {
return sessPer;
}
public void setSessPer(float sessPer) {
this.sessPer = sessPer;
}
public String getPerformance() {
return performance;
}
public void setPerformance(String performance) {
this.performance = performance;
}

}

最佳答案

NU/A9/45055 是数字吗?或者应该是一个字符串?将 '' 放在此文本周围,或者更好地使用参数

Query query=sessionn.createQuery("from org.faculty.entity.StuAcadDetails where enroll=:enrollNo").setParameter("enrollNo",enroll).list()

PS:检查上面的修改,ENROLLMENT_NUMBER 必须更改为 enroll;和类名也是完全合格的。


试试这个标准;相当于你的查询

List<StuAcadDetails> detail=(List<StuAcadDetails>) sessionn.createCriteria(StuAcadDetails.class)
.add(Restrictions.idEq(enroll))
.list()

关于mysql - Hibernate错误-org.hibernate.hql.internal.ast.QuerySyntaxException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21981206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com