
hibernate查询属性问题,而不是查询整个对象对应的表
查表的最大id结尾。这样写查查不了:Stringhql="selectmax(sale.id)fromSaleChanceEntitysale";Queryq=sessi...
查表的最大id结尾。这样写查查不了:
String hql="select max(sale.id) from SaleChanceEntity sale";
Query q=session.createQuery(hql);
List l=q.list();
Iterator i=l.iterator();
int maxId=0;
while(i.hasNext()){
Object obj[]=(Object[])i.next();
maxId=(Integer)obj[0];
System.out.println(maxId);
}
return maxId;
请问该怎样写? 展开
String hql="select max(sale.id) from SaleChanceEntity sale";
Query q=session.createQuery(hql);
List l=q.list();
Iterator i=l.iterator();
int maxId=0;
while(i.hasNext()){
Object obj[]=(Object[])i.next();
maxId=(Integer)obj[0];
System.out.println(maxId);
}
return maxId;
请问该怎样写? 展开
2个回答
展开全部
String hql="select max(sale.id)"from SaleChanceEntity sale";
List ids=session.createQuery(hql).list();
int maxId=1;//初始化maxId
if(ids==null){//判断是否查询到了结果
return maxId;
}
maxId=(Integer)ids.get(0);
return maxId;
List ids=session.createQuery(hql).list();
int maxId=1;//初始化maxId
if(ids==null){//判断是否查询到了结果
return maxId;
}
maxId=(Integer)ids.get(0);
return maxId;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询