星空网 > 软件开发 > Java

hibernate 返回新插入数据的Id

例如 表明 studentInfo

String sql="set set nocount on studentInfo(列名,列名) values('值','值');select @@identity as inserId";

  

 

java代码:

public int executeCount(String sql, Map<String, Object> paramMap) {		Session session = sessionFactory.getCurrentSession();		Query query = session.createSQLQuery(sql);		if (paramMap != null && paramMap.size() > 0) {			for (Entry<String, Object> entry : paramMap.entrySet()) {				Object value = entry.getValue();				if (value != null && value.getClass().isArray()) {					query.setParameterList(entry.getKey(),							Arrays.asList((Object[]) value));					continue;				}				query.setParameter(entry.getKey(), entry.getValue());			}		}		List<?> list = query.list();		if (list != null && list.size() > 0) {			if(list.get(0)!=null){				return Integer.parseInt(list.get(0).toString());			}		}		return 0;	}

  在dao层调用

this.executeCount(sql, map);

  注:map 放的是添加的值




原标题:hibernate 返回新插入数据的Id

关键词:Hibernate

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

“苏拉”“海葵”来袭!多家船司发布紧急通知:https://www.kjdsnews.com/a/1602928.html
918亿!中远海控公布2023年上半年业绩:https://www.kjdsnews.com/a/1602929.html
布局东南亚!Temu或将上线更多站点:https://www.kjdsnews.com/a/1602930.html
客户案例 | 中国至墨西哥精密仪器空运运输:https://www.kjdsnews.com/a/1602931.html
出口增速承压!全国港口1-7月吞吐量发布:https://www.kjdsnews.com/a/1602932.html
印度:笔记本电脑进口限制不会推迟!:https://www.kjdsnews.com/a/1602933.html
Lazada与菲律宾银行合作,引入BNPL支付服务:https://www.kjdsnews.com/a/1842118.html
Lazada与菲律宾银行合作,引入BNPL支付服务:https://www.goluckyvip.com/news/218218.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流