我无法获取结果,create查询正在执行,但之后将其转换为list无法工作。请帮我解决这个问题。为什么它没有被转换成列表我无法获取结果,创建查询正在被执行,但之后将它转换成列表不起作用。请帮我解决这个问题。为什么它没有被转换成列表
表脚本
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;
}
错误日志
null
AnswerEntity类
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;
}}
您的实体类中有属性message
,但数据库中没有相应的列。这在堆栈跟踪中可以清楚地识别出来:
ORA-00904: "ANSWERENTI0_"."MESSAGE": invalid identifier
如果要将该信息存储在数据库中,则需要创建列,或者从实体类中删除该信息,或者用@transient
标记该信息,以要求hibernate在SQL查询中忽略该信息,如以下问题所示:Make hibernate ignore class variables that not mapped(使hibernate ignore(使hibernate ignore class variables that not mapped)
问题内容: 安慰: 问题: 当我从类执行函数时,就会发生这种情况。这是怎么回事 问题答案: 如下更改查询: 否则如下: 中相应的比较 ,其中 子句是具有文字,而不是另一列。因此,必须在第一种情况下用引号引起来,或者在第二种情况下使用绑定变量。
嗨,你能帮我解决这个问题吗。我在MySQL DB中连接了这个应用程序,每次运行这个作业从DB中取数据时,我总是会得到这个异常(参见添加了Java类、DAO和方法以及apache DBCP2配置的全栈跟踪)。 null
目前,我在为springboot项目获取mysql数据时遇到了一个问题: 编辑:Application.Properties 我能够使/test/welcome映射工作,因此我相信我对服务和控制器的实现是正确的。所以我想知道我是不是在访问存储库中的数据库时犯了一个错误,还是应该使用JpaRepository而不是CrudRepository并使用显式查询? 编辑堆栈跟踪:org.springfra
我已经将支持JAR和jdbc驱动程序添加到我的项目中,但我仍然得到了低于例外情况 getting找不到resultset异常错误执行load命令:getting sqlgrammerexception 我的配置文件
问题内容: 我正在创建一个宁静的API,它将使用服务器中的json。但是我遇到了异常: org.springframework.web.client.RestClientException:无法提取响应:在org.springframework找不到响应类型为[[Lexamples.dto.DummyDTO;]]和内容类型为[text / json; charset = utf-8]的HttpMe
我正在创建一个restful API,它将使用来自服务器的json。但我得到了以下例外: 组织。springframework。网状物客户RestClientException:无法提取响应:未找到响应类型[[Lexamples.dto.DummyDTO;]的合适HttpMessageConverter和org.springframework.web.client.HttpMessageConve