我在我的項目的其中一個DAO中使用了此方法。
底層的RDBMS是MS SQL Server。
se_subaccountid
在DB級別上定義爲bigint
。Hibernate - 如何強制以編程方式返回Long而不是BigInteger?
Hibernate返回給我List<BigInteger>
。
我不想有BigInteger對象,但長對象。
我如何告訴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);
}
謝謝,這樣做。 –
編輯爲使用StandardBasicTypes.LONG而不是Hibernate.LONG,因爲Hibernate「常量」以前不推薦使用,現在已完全從代碼中刪除。另一種選擇是使用LongType.INSTANCE。 –