Java Hibernate-如何通过编程强制它返回Long而不是BigInteger?
我在项目的一个DAO中使用了此方法。Java Hibernate-如何通过编程强制它返回Long而不是BigInteger?,java,hibernate,casting,Java,Hibernate,Casting,我在项目的一个DAO中使用了此方法。 底层RDBMS是MS SQL Server。 se_子科目在DB级别定义为bigint Hibernate返回给我列表 我不想要大整数对象,但想要长对象。 如何告诉Hibernate将列表返回给我? 我想在这里用这个方法编程, 因为我不希望我的更改对全球产生影响。 这有可能吗?怎么可能 @SuppressWarnings({ "rawtypes", "unchecked" }) public List<Long> getAllCheckSubAc
底层RDBMS是MS SQL Server。
se_子科目
在DB级别定义为bigint
Hibernate返回给我列表
我不想要大整数对象,但想要长对象。
如何告诉Hibernate将
列表返回给我?
我想在这里用这个方法编程,
因为我不希望我的更改对全球产生影响。
这有可能吗?怎么可能
@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);
}
@SuppressWarnings({“rawtypes”,“unchecked”})
公共列表getAllCheckSubAccounts(){
Object res=getHibernateTemplate().execute(新的HibernateCallback()){
公共对象doInHibernate(会话会话)抛出HibernateeException、SQLException{
字符串sql=
“选择”+
" " +
“不同的sa.se_子账户为cid”+
" " +
“从”+
“子账户sa”+
“sa.accountid=a.accountid上的内部联接帐户a”+
“sa.mb_id=m.mb_id上的内部联接乘积m”+
“where”+
“(a.se_id=2)”+
“及”+
“(sa.se_subaccounted不为空)”+
“及”+
“(m.mb_状态不在(128512))”+
“订购人”+
“sa.se_子账户asc”;
SQLQuery=session.createSQLQuery(sql);
返回query.list();
}
});
返回((列表)res);
}
Hibernate从数据库元数据中获取BigInteger。您可以通过以下方式进行覆盖:
query.addScalar(“nextval”,LongType.INSTANCE)
这里有类似的线程:
这将使它返回整数,而不是长整数。我认为您的意思是LongType.INSTANCE.Edited使用StandardBasicTypes.LONG而不是Hibernate.LONG,因为Hibernate“常量”以前被弃用,现在从代码中完全删除。另一种选择是使用LongType.INSTANCE。
sess.createSQLQuery("SELECT * FROM CATS")
.addScalar("cid", StandardBasicTypes.LONG)