views:

41

answers:

2

if i use table name instead of class name in HQL query like this:

  select classname.field name as obj from table name

and i have specified mapping in hbm file. but it show exception: table name is not mapped

and second thing is i have use on keyword in query then it show exception: unexpected token: on

+1  A: 

HQL is not SQL. So, when you intend to use table name instead of class name, or try to use database specific words like ON, you should create SQL, not HQL. I mean use methods like createNativeQuery() and provide the result mapping too.

Adeel Ansari
+3  A: 

The mapping in the hbm file tells Hibernate which table the entity corresponds to, but you still always use the class name in your HQL queries.

If you do actually want to execute native SQL, refer to this.

William