Issue Type: Bug Bug
Affects Versions: 4.1.5.SP1
Assignee: Unassigned
Components: query-hql
Created: 22/Oct/12 8:35 AM
Description:

We have the following Entities defined:

@Entity
@Table(name = "table1")
public class Table1 implements VersionSupport, Persistable<Integer>

{ @Id @GeneratedValue(strategy = GenerationType.AUTO) @Basic(optional = false) @Column(name = "table1_id", nullable = false) private Integer table1Id; @Basic(optional = true) @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "table2_refid") private Table2 table2; }

@Entity
@Table(name = "table2")
@Indexed
public class Table2 implements Persistable<Integer>, Auditable, VersionSupport

{ @Id @GeneratedValue @DocumentId @Column(name = "table2_id", nullable = false) private Integer table2Id; @Field @Column(name = "matchcode", nullable = false) private String matchcode; }

(shortend of course)

If I try to do a HQL-Query like the following, I get a "CROSS JOIN" instead of a "INNER JOIN":

<code>
StringBuilder sb = new StringBuilder();

sb.append("from Table1 where table2.matchcode = :refid");

Query query = sessionFactory.getCurrentSession().createQuery(sb.toString());
query.setInteger("refid", value);

List<Table1> table1List = (List<Table1>) query.list();

return table1List;
}
</code>

HQL then generates me the following sql:

<code>
select ...
from Table1 t1 CROSS JOIN Table2 t2
where t1.table2_id = t2.id
and matchcode = ...
</code>

instead of
<code>
select ...
from Table1 t1 INNER JOIN Table2 t2 on t1.table2_id = t2.id
where matchcode = ...
</code>
which I will get if I do a explicit join:

<code>
StringBuilder sb = new StringBuilder();

sb.append("from Table1 t1 join t1.table2Id where table2.matchcode = :refid");

Query query = sessionFactory.getCurrentSession().createQuery(sb.toString());
query.setInteger("refid", value);

List<Table1> table1List = (List<Table1>) query.list();

return table1List;
}
</code>

That happens although documentation tells me in different way:
http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/queryhql.html#queryhql-joins-forms
<code>
HQL supports two forms of association joining: implicit and explicit.

The queries shown in the previous section all use the explicit form, that is, where the join keyword is explicitly used in the from clause. This is the recommended form.

The implicit form does not use the join keyword. Instead, the associations are "dereferenced" using dot-notation. implicit joins can appear in any of the HQL clauses. implicit join result in inner joins in the resulting SQL statement.

from Cat as cat where cat.mate.name like '%s%'</code>

Who can help me in this case? I don't want to get ANY CROSS JOIN in my Program. In this case I have mapped my refid as nullable as it has to be filled later on in my program. But at the time I create this object it is nullable as I do not have this Object.

Either way -> I turned it to not null and it happened again...

Environment: Informix 11.50
Spring
Project: Hibernate ORM
Labels: hibernate query informix hql
Priority: Major Major
Reporter: eMundo GmbH
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira