Querysyntaxexception:unexpected token:on [null] near line 1, column 135_bug harvester

Source: Internet
Author: User
Tags postgresql


Getting error that unexpected Token:on near line 1, column 135



Solution Method:
No Defined Association in hbm.xml file



Hibernate HQL Inner Join





Query query = Session.createquery ("From Cat cat inner JOIN owner 
owner where owner.") Name = ' Duke ' ');


No Defined Association in hbm.xml file





Query query = Session.createquery ("From Cat cat inner join owner
 owner on Cat.") ownerID = owner. Id where owner. Name= ' Duke ' ");
But the query would fail with the following error message:

caused by:org.hibernate.hql.ast.QuerySyntaxException: 
Unexpected Token:on near line 1, column XX


Native SQL is the solution





Import Org.hibernate.SQLQuery;
...
SQLQuery query = Session.createsqlquery ("Select cat.* from cat inner join owner"
 cat.owner_id = owner.id where owner . Name=:username ");
Query.addentity (cat.class);
Query.setinteger ("username", ' Duke ');
List =query.list ();


The Hibernate framework when mapping database tables, is to convert a table to an entity class, using the Operation data object instead of the action table, which is the same as the Java language facing the opposite image of the original operation, HQL provides a richer and more flexible, more powerful query capabilities, HQL statements corresponding to the entity class and entity class attributes are encapsulated, Instead of the table name, the query statement is JavaBean the entity object name, where the JavaBean entity property name is not after the field.



Session.createquery (SQL);
SESSION.CREATESQLQUERYSQL);



Querysyntaxexception:unexpected token:user_id near Line 1, column 29





Querysyntaxexception:unexpected token:user_id near Line 1, column
 [from model. Demand d where D user_id=? The ORDER by d.id DESC]

query syntax error

user_id the correct wording in Demand user from 
 Demand d where d.user.id=? ORDER BY d.id Desc


Unexpected token:null near line 1, column 290


Org.hibernate.hql.internal.ast.QuerySyntaxException: 
unexpected Token:null near line 1, column 290 
[select Count (*) from Cn.com.taiji.sample.entity.User T 
where 1=1 and (T.name like:username or T.namepy like:username >t.loginname Like:username and T.status =:status and not 
exists (select B.user from Cn.com.sample.entity.UserRole bwhere b.role.id =:roleid and b.user.id = t.id)]



This is my report error, the reason for the error is grammatical format errors, the entire HQL statement is here,

combined with the online search solution, summed up as follows:


1, the extra space;


2, string quotes should be single quotes;


3, =: should be together, There is no space in the middle, ' like: ' The intermediary needs to have space, in fact, here is not so rigorous, just in case;


4, parentheses, I have the problem is that the left parenthesis than the right parenthesis more than one;


5, a SQL or HQL statement can only have an order By (in the absence of a subquery), so if there are multiple sort criteria that need to be referenced, then add a comma between each condition, for example: 

from Topic T-order by T.posttime Desc,t.lastupdatedtime ASC;

Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

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.