Search code examples
javaspringhibernatethymeleafhql

Order is not mapped(INSERT HQL)


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


Solution

  • i solved it with: Query query = session.createSQLQuery("INSERT INTO orders (text, status, customer) VALUES (:text, :status, :customer)"); (sql request)