InvalidDataAccessResourceUsageException和SQLGrammarException

时间:2018-04-14 11:25:59

标签: spring hibernate spring-mvc exception sqlexception

当我尝试更新hibernate实体时,我得到了这个例外。可能是什么问题呢?

@Service
@Transactional
public class ProductServiceImpl implements ProductService {
...
@Override
public void updateAllStock() {
    products.getAllProducts().stream()
            .filter(e -> e.getUnitsInStock() < 500)
            .forEach(e -> products.updateStock(e.getProductId(), 
                       1000));
}

DAO

@Repository
public class ProductDaoImpl implements ProductDao {
...
@Override
public void updateStock(int productId, int numOfUnits) {
    Session currentSession = factory.getCurrentSession();
    Product product = currentSession.load(Product.class, productId);
    product.setUnitsInStock(product.getUnitsInStock() + numOfUnits);
}

编辑:添加堆栈跟踪:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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', description='Apple iPhone 6s smartphone with 4.00-inch 640x1136' at line 1
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
com.mysql.jdbc.Util.getInstance(Util.java:387)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:942)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)

我认为hibernate配置有问题吗?

0 个答案:

没有答案