gpt4 book ai didi

java - 我正在尝试从数据库收集数据并在 Hibernate 中使用 String 作为参数返回其对象

转载 作者:行者123 更新时间:2023-11-30 06:20:20 24 4
gpt4 key购买 nike

我试图使用参数ProductId和以下代码从表ProductInformation收集数据,但我得到的只是

unexpected token: * near line 1, column 8 [select * from com.koshayali.Koshayalinepal.model.ProductInformation where ProductId = :ProductId]

代码:

@Override
@Transactional
public List<ProductInformation> getSearchId(String ProductId) {
Session session=sessionFactory.openSession();
String sql = "select * from ProductInformation where ProductId = :ProductId";
Query query = session.createQuery(sql).setParameter("ProductId", ProductId);;
List<ProductInformation> produ = query.list();
session.close();
return produ;
}

最佳答案

先检查productId long类型还是String类型如果数据库productId是long类型,则将字符串转换为long值

 public List<ProductInformation> getSearchId(String ProductId){
String getproductInfromationQuery = "FROM ProductInformation where ProductId =:ProductId";
Query queryObj = sessionFactory.getCurrentSession().createQuery (getproductInfromationQuery);
queryObj.setParameter("ProductId", ProductId);
@SuppressWarnings("unchecked")
List<ProductInformation> productList = queryObj.list();
return productList;
}

关于java - 我正在尝试从数据库收集数据并在 Hibernate 中使用 String 作为参数返回其对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48294585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com