我无法获取结果,创建查询正在执行,但之后将其转换为列表无效。请帮我解决这个问题。 为什么它没有被转换成列表 我无法获取结果,创建查询正在执行但是将其转换为列表之后无效。请帮我解决这个问题。 为什么它没有被转换成列表
Tablescript
CREATE TABLE Answer(
answerId INTEGER,
questionId INTEGER NOT NULL,
userId varchar2(40) NOT NULL,
answerString VARCHAR2(400) NOT NULL,
CONSTRAINT pk_Answer_answerId PRIMARY KEY(answerId)
);
bean类
public class Answer {
private Integer answerId;
private Integer questionId;
private String userId;
private String answerString;
private String message;
public Integer getAnswerId() {
return answerId;
}
public void setAnswerId(Integer answerId) {
this.answerId = answerId;
}
public String getAnswerString() {
return answerString;
}
public void setAnswerString(String answerString) {
this.answerString = answerString;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Integer getQuestionId() {
return questionId;
}
public void setQuestionId(Integer questionId) {
this.questionId = questionId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}}
控制器方法是:
$scope.tagForm.getAnswer = function(val) {
alert("hi");
window.location = "#/answer";
$scope.tagForm.ans = null;
var data = JSON.stringify($scope.tagForm);
$http.post(URI + "tag/ans/"+val,data).then(function(response) {
alert("hey");
//var string=response.data;
//var formattedString = string.join("\n");
//$scope.askForm.message =formattedString;
$scope.tagForm.ans =response.data;
//alert($scope.tagForm.message);
}, function(response) {
$scope.tagForm.message = null;
});
};
@SuppressWarnings({ "unchecked", "unused" })
public Map<Integer, String> getAnswer(Integer question) throws Exception {
Map<Integer, String> quesString = null;
SessionFactory sessionFactory = null;
Session session = null;
List<AnswerEntity> custList1 = new ArrayList<AnswerEntity>();
try {
quesString = new LinkedHashMap<Integer, String>();
sessionFactory = HibernateUtility.createSessionFactory();
session = sessionFactory.openSession();
AnswerEntity tag = new AnswerEntity();
// Question q=new Question();
// q.setTagId(question);
// ques.setQuestionString(question.getQuestionString());
System.out.println("dao" + question);
// session.persist(ques);
// session.getTransaction().begin();
System.out.println("before query exec");
Query query = session
.createQuery("from AnswerEntity where questionId=?");
query.setInteger(0, question);
System.out.println(query);
System.out.println("after query exec");
custList1 = query.list();
System.out.println(custList1.size());
// List list = query.list();
for (AnswerEntity tagEntity : custList1) {
// System.out.println("Question ID=>"+tagEntity.getQuestionId()+"\nQuestion String=>"+tagEntity.getQuestionString());
// List<String> newList = new ArrayList<String>();
Answer a = new Answer();
a.setQuestionId(tagEntity.getQuestionId());
a.setAnswerString(tagEntity.getAnswerString());
// newList.addAll(getTag(tagEntity.getQuestionId()));
// String a=String.valueOf(tagEntity.getQuestionId());
quesString.put(a.getQuestionId(), a.getAnswerString());
// quesString.add(a);
// quesString.addAll(newList);
}
// session.getTransaction().commit();
} catch (HibernateException exception) {
exception.printStackTrace();
DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
Logger logger = Logger.getLogger(this.getClass());
logger.error(exception.getMessage(), exception);
throw new Exception("DAO.TECHNICAL_ERROR");
} catch (Exception exception) {
exception.printStackTrace();
DOMConfigurator.configure("src/com/infy/resources/log4j.xml");
Logger logger = Logger.getLogger(this.getClass());
logger.error(exception.getMessage(), exception);
throw exception;
} finally {
if (session.isOpen() || session != null) {
session.close();
}
}
return quesString;
}
错误日志
org.hibernate.exception.SQLGrammarException:无法提取ResultSet 在org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:80) 在org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) 在org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126) 在org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:91) 在org.hibernate.loader.Loader.getResultSet(Loader.java:2066) 在org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863) 在org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839) 在org.hibernate.loader.Loader.doQuery(Loader.java:910) 在org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355) 在org.hibernate.loader.Loader.doList(Loader.java:2554) 在org.hibernate.loader.Loader.doList(Loader.java:2540) 在org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370) 在org.hibernate.loader.Loader.list(Loader.java:2365) 在org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497) 在org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387) 在org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236) 在org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300) 在org.hibernate.internal.QueryImpl.list(QueryImpl.java:103) 在com.infy.dao.TagDAOImpl.getAnswer(TagDAOImpl.java:122) 在com.infy.service.TagServiceImpl.getAnswer(TagServiceImpl.java:55) 在com.infy.api.TagAPI.fetchTagList2(TagAPI.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory $ 1.invoke(ResourceMethodInvocationHandlerFactory.java:81) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher $ 1.run(AbstractJavaResourceMethodDispatcher.java:144) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider $ ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) 在org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) 在org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) 在org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) 在org.glassfish.jersey.server.ServerRuntime $ 2.run(ServerRuntime.java:317) 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:271) 在org.glassfish.jersey.internal.Errors $ 1.call(Errors.java:267) 在org.glassfish.jersey.internal.Errors.process(Errors.java:315) 在org.glassfish.jersey.internal.Errors.process(Errors.java:297) 在org.glassfish.jersey.internal.Errors.process(Errors.java:267) 在org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) 在org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:298) 在org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) 在org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471) 在org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425) 在org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383) 在org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336) 在org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) 在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) 在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:620) at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61) 在java.lang.Thread.run(未知来源) 引起:java.sql.SQLSyntaxErrorException:ORA-00904:&#34; ANSWERENTI0 _&#34;。&#34; MESSAGE&#34;:无效标识符
AnswerEntity Class
public class AnswerEntity {
@Id
@GeneratedValue(generator = "generatorName")
private Integer answerId;
private Integer questionId;
private String userId;
private String answerString;
private String message;
public Integer getAnswerId() {
return answerId;
}
public void setAnswerId(Integer answerId) {
this.answerId = answerId;
}
public String getAnswerString() {
return answerString;
}
public void setAnswerString(String answerString) {
this.answerString = answerString;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Integer getQuestionId() {
return questionId;
}
public void setQuestionId(Integer questionId) {
this.questionId = questionId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}}
答案 0 :(得分:1)
您的实体类中有属性message
,但您在数据库中没有相应的列。这在堆栈跟踪中清楚地标识出来:
ORA-00904: "ANSWERENTI0_"."MESSAGE": invalid identifier
如果要将该信息存储在数据库中或将其从实体类中删除,或者使用@Transient
将其标记为要求hibernate在SQL查询中忽略它,则需要创建列,如下所示:{ {3}}