我写了这个hql查询以更新对象
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Query modelQuery = session.createQuery("from Model m where m.modelId=:modelId");
modelQuery.setInteger("modelId", car.getModel().getModelId());
Model carModel = (Model) modelQuery.uniqueResult();
Query query = session.createQuery("update Car set model = :model,price=:price,quantity=:quantity,carDesc=:cardesc,enginCc=:engincc,trans=:trns,noOfCylinder=:noOfCylindr,topSpeed=:topSpeed,fuelType=:fuelType,fuelCapacity=:fuelCapacity "
+ " where carId = :carId");
query.setEntity("model", carModel);
query.setParameter("price", car.getPrice());
query.setParameter("quantity", car.getQuantity());
query.setParameter("cardesc", car.getCarDesc());
query.setParameter("engincc", car.getEnginCc());
query.setParameter("trns", car.getTrans());
query.setParameter("noOfCylindr", car.getNoOfCylinder());
query.setParameter("topSpeed", car.getTopSpeed());
query.setParameter("fuelType", car.getFuelType());
query.setParameter("fuelCapacity", car.getFuelCapacity());
query.setParameter("carId", car.getCarId());
int result = query.executeUpdate();
System.out.print("RESULT----->"+result);
然而,它不会抛出任何异常,它只在控制台中给出0