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;