英文:
Order is not mapped(INSERT HQL)
问题
我有一个问题。我需要显示从该行获取的值并将其传递到数据库。我正在使用timelif,所以我得到错误"Order is not mapped",实际上是指向第31行,指的是我的HQL查询。结构:我在字段中输入一个单词,timelif将其传递给spring的post请求,然后将其传递给函数。需要以某种正确的方式编写请求,以便将文本输入到数据库。我的代码:
@PostMapping("/")
public String createOrder(@ModelAttribute("order") Orderdao orderdao, String text) {
orderdao.createOrder(text);
return "redirect:/";
}
函数:
public void createOrder(String text) {
Transaction tx = null;
try (Session session = BogPomogi.getSessionFactory().openSession()) {
session.beginTransaction();
System.println(text);
Query create = session.createQuery("insert into Order(text) select text from text");
int result = create.executeUpdate();
session.getTransaction().commit();
session.close();
}
}
请帮助我。
英文:
I have a problem. I need to display the value from the line and transfer it to the database. I'm using a timelif, and so, I get the error "Order is not mapped", and points to line 31, in fact, to my HQL query. Structure: I enter a word in the field, the timelif transfers it to the post request of the spring, and the same transfers it to the function. It is necessary to write the request somehow correctly so that the text is entered into the database. My code:
public String createOrder (@ModelAttribute("order") Orderdao orderdao, String text){
orderdao.createOrder(text);
return "redirect:/";
}
Function:
public void createOrder(String text) {
Transaction tx = null;
try (Session session = BogPomogi.getSessionFactory().openSession()) {
session.beginTransaction();
System.out.println(text);
Query create = session.createQuery("insert into Order(text)" + "select text from text");
int result = create.executeUpdate();
session.getTransaction().commit();
session.close();
}
Help me please
答案1
得分: 0
我用以下方式解决了它:Query query = session.createSQLQuery("INSERT INTO orders (text, status, customer) VALUES (:text, :status, :customer)");
(SQL请求)
英文:
i solved it with: Query query = session.createSQLQuery("INSERT INTO orders (text, status, customer) VALUES (:text, :status, :customer)");
(sql request)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论