Reputation: 455
In the hbm.xml, after an enhancement, I have 2 mapping entry for the class ABC, both are mapped to the table ABC_TABLE
<class entity-name="ABC" name="model.ABC" table="ABC_TABLE">
<!-- property tags and id tag -->
</class>
<class entity-name="LazyABC" name="model.ABC" table="ABC_TABLE">
<!-- property tags and id tag -->
</class>
Before the enhancement, the hbm.xml only have the entity-name="ABC" mapping for the ABC class.
After such enhancement, the original HQL query code
select new ABC(a.abcId, a.abcContent, a.abcEnding) from ABC a where....
throws exception when executed.
The exception is
org.springframework.orm.hibernate3.HibernateQueryException: Unable to locate class [ABC]
caused by
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate class [ABC]
Then I found solution on internet, just to change the ABC constructor name to full path of the class, like
select new model.ABC(a.abcId, a.abcContent, a.abcEnding) from ABC a where....
Then the problem is fixed and no exception is thrown in executing the query!
But, I just don't know why the hibernate handling is like that.
Can somebody tell me the underlying reason why it would be the solution?
Thanks. :)
Upvotes: 0
Views: 1932
Reputation: 10083
First of all if you need object based results. Use Criteria
API.
You may have a valid import for ABC
class. But HQL
doesn't know the package name of the class, Because it is String. So you should provide the complete path including package name.
Upvotes: 1