Hibernate sqlquery MySQL alias problem

Source: Internet
Author: User

Over the two days, the query presentation for some order data (because some data would like to be calculated directly in SQL) increases efficiency. So I used the hql I assembled.


Before yes SQL is as follows:

SQL for duly cast/returned goods
select o.id ,o.sn, o.community_id , o.seller_id , o.status ,  O.pay_rate ,o.payment_id,o.payment_profit,o.cwy_profit, o.amount, o.delivery_fee ,o.bank_ Pay , o.completed_date ,o.create_time , o.red_packet_pay , o.coupon_pay  ,o.cwy_profit,  (o.pay_rate * o.bank_pay / 100)  as poundage    (O.cwy_profit * o.bank_pay)  as profit ,  (o.payment_profit *  O.BANK_PAY&NBSP;/&NBSP;100)  as pay_profit , c.name as comm_name ,  S.name as shop_name , s.checkout_days , s.deduct , ri.shop_id as  red_shop_id , ri.red_money as ri_money , qi.shop_id as coupon_ Shop_id , qi.coupon_money as qi_money, d.id as diff_fee_id,d.status as  diff_status,d.diff_fee as fee,d.balance_id from  ' Order '  o LEFT JOIN diff_fee d ON  d.order_id = o.id left join community c on o.community_id =  c.id left join shop s on o.seller_id = s.id left join  Red_receives r on o.red_recevices_id = r.id left join red_packet_infos  ri ON r.red_id = ri.id LEFT JOIN coupon_receives q ON  o.coupon_recevices_id = q.id left join coupon_infos qi on q.coupon_id  = qi.id where o.community_id > 0 and o.payment_id != 0  AND o.status IN  ( 4,5,7 )  and unix_timestamp ( o.completed_date  )  >= :start_time and unix_timestamp ( o.completed_date )  <=  :end_time aNd o.seller_id = :seller_id order by completed_date desc


However, has been an error, said

1] (Jdbcexceptionreporter.java:234)-Column' shop_id 'Not found.

Back to me. The column about shop_id was deleted and continues to be reported to the next column Coupon_money not found. Very depressed, all kinds of possibilities have been thought of, also called colleagues to help see, can not find the reason. After the column to the home, found that it was used as to the other alias caused by, the following changes into the statement below, on the line.


Sql= "Select O.id, O.sn, o.community_id, o.seller_id, O.status, O.pay_rate, O.payment_id,o.payment_profit,o.cwy_profit , O.amount, O.delivery_fee, O.bank_pay, Unix_timestamp (o.completed_date), O.create_time, O.red_packet_pay, O.coupon_ Pay, O.cwy_profit, (O.pay_rate * o.bank_pay/100) as poundage, (O.cwy_profit * o.bank_pay) as profit, (O.payment_profit * o.bank_pay/100) as Pay_profit, C.name  , S.name  , S.checkout_days, S.deduct, ri.shop_id, Ri.red_money  , qi.shop_id  , Qi.coupon_money, D.id, D.status, D.diff_fee, d.balance_id from ' order ' O left JOIN diff_fee D On d.order_id = O.id LEFT Join Community c on o.community_id = C.id left join shop s on o.seller_id = S.id LEFT Join Red_r Eceives r on o.red_recevices_id = r.id left joins Red_packet_infos ri on r.red_id = ri.id left joins coupon_receives Q on O. coupon_recevices_id = q.id left JOIN coupon_infos qi on q.coupon_id = qi.id WHERE o.community_id > 0 and o.payment_id! = 0 and O.status =10 and UNIX_timestamp (o.completed_date) >= "+balance.getstarttime () +" and Unix_timestamp (o.completed_date) <= "+ Balance.getendtime () + "and o.seller_id =" +form.getshopid () + "ORDER by Completed_date DESC";



See netizens there is a solution, do not know, I have not tried, also record it

How to Save:

Troubled me for a long time, find a lot of information, the problem is very simple, is the driver does not support the problem of aliases, recorded here, for the Yimeimei build Bridge!!! When connecting to MySQL database, add useoldaliasmetadatabehavior=true this parameter!!!!


jdbc.url=jdbc\:mysql\://127.0.0.1\:3306/db?useunicode\=true&characterencoding\=utf8& Useoldaliasmetadatabehavior=true


Hibernate sqlquery MySQL alias problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.