Hibernate中的order的排序
selectuserId,userName,gameId,innerId,gameName,firmName,avg(onlineTimeLong)asonlinefro...
select userId ,userName, gameId,innerId,gameName, firmName,avg(onlineTimeLong) as online
from u_onlinetimelong
group by userId,userName,gameId order by online desc
这条sql语句在数据库中可以执行 可是怎么到了hibernate中就执行不了
呢
select userId ,userName, gameId,innerId,gameName, firmName,avg(onlineTimeLong) as online
from u_onlinetimelong
group by userId,userName,gameId order by avg(onlineTimeLong) desc
最后我改成这样才能执行。
究竟是什么原因造成的 具体需要怎么修改啊
Unknown column 'online' in 'order clause' 老是显示这个错误 展开
from u_onlinetimelong
group by userId,userName,gameId order by online desc
这条sql语句在数据库中可以执行 可是怎么到了hibernate中就执行不了
呢
select userId ,userName, gameId,innerId,gameName, firmName,avg(onlineTimeLong) as online
from u_onlinetimelong
group by userId,userName,gameId order by avg(onlineTimeLong) desc
最后我改成这样才能执行。
究竟是什么原因造成的 具体需要怎么修改啊
Unknown column 'online' in 'order clause' 老是显示这个错误 展开
3个回答
展开全部
Hib的检索方式
1‘导航对象图检索方式。通过已经加载的对象,调用.iterator()方法可以得到order对象
如果是首次执行此方法,Hib会从数据库加载关联的order对象,否则就从缓存中得到。
2‘OID检索方式。通过session的get,load方法知道了OID的情况下可以使用
3‘HQL检索方式。使用面向对象的HQL查询语句session的find方法利用HQL来查询
4‘QBC检索方式。利用QBCAPI来检索它是封装了基于字符串的查询语句
5‘本地的SQL检索方式。使用本地数据库的SQL查询语句Hib会负责把检索到的JDBC结果集映射为持久化对象图。
Order的用法
一、名词order作“顺序”、“次序”、“整齐”、“秩序”解:
1. The machine is in good working order. 机器运转良好。
2. The four seasons follow in order. 四个季节依次轮换。
3. Our laboratory is kept in good order. 我们的实验室保持整齐。(句中in good order为主语补语。)
4. In case the device is out of order, you have to repair it at once. 如果该装置发生故障,你就得马上修理。
5. N2, H2 and He, in the order named, are more difficult to liquefy than air. N2,H2和He比空气难于液化的程度按其顺序依次递增。
6. A list of some of the common metals in the order of their activity is given below. 下面列出了某些金属按其活泼顺序排列的一个表格。
二、名词order作“订货”、“订货单”、“数量级或范围”、“命令”解:
1. The factory has received an order for 2,000 machine tools. 工厂受到了一张要买2,000 台机床的订货单。
2. These machines are made to order. 这些机器是定做的。(to order指按照订货要求的样式而言。)
3. The average diameter of an atomic nucleus is of the order 10 or 10 centimeter. 原子核平均直径在10(10的负12次方)或10(10的负13次方)厘米范围内。
4. Maximum signal currents are of the order of 50 ma. 最大信号电流是在50毫安这个数量级。
5. He gave orders for the work to be started. (=…orders that the work should be started.)他下令开始工作。
三、用“in order+带to的不定式”表示目的状语:
1. We are working hard (in order) to build socialism in China. 我们正在为中国建设社会主义而努力工作。
2. In order to measure the resistance of a conductor, it is necessary to have some fixed standard. 为了测量导体的电阻,就要有某种固定的标准。
3. They took off their shoes upon (on) entering, in order not to soil the mats. 他们进来时都脱鞋,免得弄脏地毯。
4. In order to adjust the level, we may screw the bolt up or down. 我们上下拧动螺钉以调节该水平仪。
注1:有时可省略in order,而直接用不定式表示目的状语:
We have produced a lot of tractors (in order) to meet the needs of our agriculture.我们生产了许多拖拉机以满足我们农业的需要。
(In order) To understand these uses, you must know some of the properties of oxygen.要了解这些用途,你必须知道氧的某些性质。
注2:注意in order后面出现不定式的逻辑主义for…的情况:
In order for two forces to neutralize each other, they must act on the same object.为了使两个力互相抵消,它们必须作用于同一物体上。
注3:若用“on purpose+不定式”代替“in order +不定式”,则前者含有特地、故意意味而使目的的状语语气加强。例如:
She has left this tool on purpose for you to use.她有意把这个工具留在这里让出使用。
四、用“in order that”引导目的从句:
1. What is needed in order that electrical charges may moves? 需要什么才能使电荷运动呢?
2. In order that work can be done, in scientific sense, a force must move an object through some distance. 就科学意义来说,为了做功,力必须推动物体通过一定距离。
3. You must knock down the machines before shipping in order that they shall arrive in good shape. 你们必须在装运前拆卸这些机器以使他们完整无损到达。
4. The old worker, in order that there might be no time lost, oiled the machines himself. 为节省时间,老工人亲自给机器上油。
注:在in order that引出的目的状语从句内,常用情态动词may,might,can,could,shall等。当目的的状语从句在句末时,还常可用so that或to the end that代替in order that。
五、动词order作“定制”、“订购”、“命令”解:
1. They have ordered 1,000 oil pumps from our factory.他们已向我厂订购1,000台油泵。
2. The doctor ordered him to stay there.医生嘱咐他留在那里。(不定式短语to stay there作宾语补语)
1‘导航对象图检索方式。通过已经加载的对象,调用.iterator()方法可以得到order对象
如果是首次执行此方法,Hib会从数据库加载关联的order对象,否则就从缓存中得到。
2‘OID检索方式。通过session的get,load方法知道了OID的情况下可以使用
3‘HQL检索方式。使用面向对象的HQL查询语句session的find方法利用HQL来查询
4‘QBC检索方式。利用QBCAPI来检索它是封装了基于字符串的查询语句
5‘本地的SQL检索方式。使用本地数据库的SQL查询语句Hib会负责把检索到的JDBC结果集映射为持久化对象图。
Order的用法
一、名词order作“顺序”、“次序”、“整齐”、“秩序”解:
1. The machine is in good working order. 机器运转良好。
2. The four seasons follow in order. 四个季节依次轮换。
3. Our laboratory is kept in good order. 我们的实验室保持整齐。(句中in good order为主语补语。)
4. In case the device is out of order, you have to repair it at once. 如果该装置发生故障,你就得马上修理。
5. N2, H2 and He, in the order named, are more difficult to liquefy than air. N2,H2和He比空气难于液化的程度按其顺序依次递增。
6. A list of some of the common metals in the order of their activity is given below. 下面列出了某些金属按其活泼顺序排列的一个表格。
二、名词order作“订货”、“订货单”、“数量级或范围”、“命令”解:
1. The factory has received an order for 2,000 machine tools. 工厂受到了一张要买2,000 台机床的订货单。
2. These machines are made to order. 这些机器是定做的。(to order指按照订货要求的样式而言。)
3. The average diameter of an atomic nucleus is of the order 10 or 10 centimeter. 原子核平均直径在10(10的负12次方)或10(10的负13次方)厘米范围内。
4. Maximum signal currents are of the order of 50 ma. 最大信号电流是在50毫安这个数量级。
5. He gave orders for the work to be started. (=…orders that the work should be started.)他下令开始工作。
三、用“in order+带to的不定式”表示目的状语:
1. We are working hard (in order) to build socialism in China. 我们正在为中国建设社会主义而努力工作。
2. In order to measure the resistance of a conductor, it is necessary to have some fixed standard. 为了测量导体的电阻,就要有某种固定的标准。
3. They took off their shoes upon (on) entering, in order not to soil the mats. 他们进来时都脱鞋,免得弄脏地毯。
4. In order to adjust the level, we may screw the bolt up or down. 我们上下拧动螺钉以调节该水平仪。
注1:有时可省略in order,而直接用不定式表示目的状语:
We have produced a lot of tractors (in order) to meet the needs of our agriculture.我们生产了许多拖拉机以满足我们农业的需要。
(In order) To understand these uses, you must know some of the properties of oxygen.要了解这些用途,你必须知道氧的某些性质。
注2:注意in order后面出现不定式的逻辑主义for…的情况:
In order for two forces to neutralize each other, they must act on the same object.为了使两个力互相抵消,它们必须作用于同一物体上。
注3:若用“on purpose+不定式”代替“in order +不定式”,则前者含有特地、故意意味而使目的的状语语气加强。例如:
She has left this tool on purpose for you to use.她有意把这个工具留在这里让出使用。
四、用“in order that”引导目的从句:
1. What is needed in order that electrical charges may moves? 需要什么才能使电荷运动呢?
2. In order that work can be done, in scientific sense, a force must move an object through some distance. 就科学意义来说,为了做功,力必须推动物体通过一定距离。
3. You must knock down the machines before shipping in order that they shall arrive in good shape. 你们必须在装运前拆卸这些机器以使他们完整无损到达。
4. The old worker, in order that there might be no time lost, oiled the machines himself. 为节省时间,老工人亲自给机器上油。
注:在in order that引出的目的状语从句内,常用情态动词may,might,can,could,shall等。当目的的状语从句在句末时,还常可用so that或to the end that代替in order that。
五、动词order作“定制”、“订购”、“命令”解:
1. They have ordered 1,000 oil pumps from our factory.他们已向我厂订购1,000台油泵。
2. The doctor ordered him to stay there.医生嘱咐他留在那里。(不定式短语to stay there作宾语补语)
展开全部
Hibernate 中使用的各个列名并不是指你数据库中的列名,而是你在表配置xml中对应到类中的各个属性。在Hibernate中你使用online,实际上是直接取了online这个的属性,而这个属性又直接对应到了你的表中的online列,而不是你在前面选择列中定义的avg(online TimeLong) as online 。所以它会提示你找不到该列。
你可以试试,假如你的表里用的是userName这个字段名,在xml中把userName这个字段对应到你类中的Myname,在你的类里把userName改成Myname,然后你再用Hibernate进行查询,这时你再用userName是会报错的,应该用Myname。
你可以试试,假如你的表里用的是userName这个字段名,在xml中把userName这个字段对应到你类中的Myname,在你的类里把userName改成Myname,然后你再用Hibernate进行查询,这时你再用userName是会报错的,应该用Myname。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
online 是你查询后显示别名,不能直接用于group 和 order,必须写全或用序列号,这里是第7个。
select userId ,userName, gameId,innerId,gameName, firmName,avg(onlineTimeLong) as online
from u_onlinetimelong
group by userId,userName,gameId order by 7 desc
select userId ,userName, gameId,innerId,gameName, firmName,avg(onlineTimeLong) as online
from u_onlinetimelong
group by userId,userName,gameId order by 7 desc
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询