Update obiektu z bazy danych

0

Założenie jest proste: w URL mam dwa parametry "id"(produktu) i "count" (liczba zamówien). Id oczywiscie indentyfikuje produkt,a count ma dokonac odpowiedniego update'u do obiektu w bazie danych
Oto metoda z kontrolera


	@RequestMapping("/order")
	public String processOrder(@RequestParam("id") int productId, @RequestParam("count") int count, Model model) {
		productsService.processOrder(productId, count);
		Product product = productsService.getProductById(productId);

		model.addAttribute("product", product);

		return "order-confirmation";
	}

a oto metoda z DAO:

public void processOrder(int productId, int count) {
		Session session = sessionFactory.getCurrentSession();
		Product product = session.get(Product.class, productId);
		if (product.getUnitsInStock()<count){
			throw new IllegalArgumentException("Not enough units in store.Current amount is :"+ product.getUnitsInStock());
		}
		else{
			product.setUnitsInStock(product.getUnitsInStock() - count);
			session.saveOrUpdate(product);
			
		}

Dostaje exception

SEVERE: Servlet.service() for servlet [Webstore] in context with path [/Webstore] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement] with root cause
java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'condition='new', discontinued=0, name='Iphone7', unit_price=599, units_in_order=' at line 1


Problem jest z setterem bez którego wszystko jest OK,no ale bez którego oczywiście nie dokona się update do bazy danych.
Jaki sposobem ten setter wykonuje nieprawidłowe zapytanie?
Jak przeniosę go do kontrolera to też nie ma problemu ale w tej metodzie za chiny nie chce zadziałać.

Wymyśliłem że zamiast settera użyję po prostu nativeQuery bezpośrdnio do bazy ale wciąż mnie zastanawia co z tym pierwszym rozwiązaniem jest nie tak

0

Masz gdzieś projekt na githubie?

0

Niestety gita jeszcze nie ogarnąłem.Postaram się to zrobić jak najszybciej

1 użytkowników online, w tym zalogowanych: 0, gości: 1