Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1
Mapping documents:
Two classes: Project (1--*) ProjectTask
The Project has a customer field, and the ProjectTask has a project field that links to the parent project object.
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
MySQL 5
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
I am using the criteria query which contains a subselect that is done using th DetachedCriteria. However, the same DetachedCriteria generates correct SQL if used alone, but failed to generate the implicit join when used as a subselect of another criteria.
The following is the DetachedQuery:
Code:
DetachedCriteria dc = DetachedCriteria.forClass(ProjectTask.class, "task").
createAlias("project", "proj").
setProjection(Projections.property("task.id")).
add(Restrictions.eq("proj.customerName", "my_customer"));
When used alone:
Code:
cusEmp.getExecutableCriteria(session).list();
It generates SQL:
Code:
select this_.id as y0_ from project_task this_ inner join project proj1_ on this_.project_id=proj1_.id where proj1_.customer_name=?
However, when put it as a subselect of another criteria, the SQL generated misses the implicit join between ProjectTask and Project. The following is the subselect SQL string:
Code:
(select this0__.id as y0_ from project_task this0__ where proj1_.customer_name=?)
As you can see, the SQL is not valid because it does not even mention the table project.
I think this is a bug, can someone confirm this?