I use hibernate. There are entries in the database (category), I display these categories on the page, without outputting their id only names. After I create the product, this product should have a connection with the derived categories (with one of them). And I have a question at this point. How can I save an object by making a query with a search by category name and save? Without making 2 requests.
public void save(Products products,String category){
Criteria criteria = session.getCurrentSession().createCriteria(Categories.class);
criteria.add(Restrictions.eq("category_name", category));
Categories resCat =(Order) criteria.uniqueResult();
products.setCategor(resCat);
session.getCurrentSession().save(products);
//This method is not suitable...
}
I need this in the form of hibernate:
INSERT INTO table1 ( column1, column2, someInt, someVarChar )
SELECT table2.column1, table2.column2, 8, 'some string etc.'
FROM table2
WHERE table2.category_name = blablabla;