gpt4 book ai didi

java - Hibernate - 如何以编程方式强制它返回 Long 而不是 BigInteger?

转载 作者:行者123 更新时间:2023-12-02 11:16:23 30 4
gpt4 key购买 nike

我的项目的 DAO 之一中有此方法。
底层 RDBMS 是 MS SQL Server。
se_subaccountid定义为bigint在数据库级别。

Hibernate 返回给我 List<BigInteger> .
我不想拥有 BigInteger 对象,而是想要 Long 对象。
我如何告诉 Hibernate 返回给我 List<Long>
我想在这个方法中以编程方式执行此操作,
因为我不希望我的更改产生全局影响。
这可能吗?如何实现?

@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Long> getAllCheckSubAccounts() {
Object res = getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {

String sql =
"select " +
" " +
"distinct sa.se_subaccountid as cid " +
" " +
"from " +
"subaccount sa " +
"inner join account a on sa.accountid = a.accountid " +
"inner join product m on sa.mb_id = m.mb_id " +
"where " +
"(a.se_id = 2) " +
"and " +
"(sa.se_subaccountid is not null) " +
"and " +
"(m.mb_status not in (128, 512)) " +
"order by " +
"sa.se_subaccountid asc ";

SQLQuery query = session.createSQLQuery(sql);
return query.list();
}
});

return ((List<Long>) res);
}

最佳答案

sess.createSQLQuery("SELECT * FROM CATS")
.addScalar("cid", StandardBasicTypes.LONG)

这里有类似的线程:
How to specify data type when using native SQL query?

关于java - Hibernate - 如何以编程方式强制它返回 Long 而不是 BigInteger?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22248872/

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