Order is not mapped(INSERT HQL)

huangapple go评论61阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年2月10日 03:53:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75403765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定