Issue Type: Improvement Improvement
Affects Versions: 3.6.10
Assignee: Unassigned
Components: annotations, query-sql
Created: 27/Sep/12 4:32 AM
Description:

@Entity
public class LineData
{
@Id
public String getId() { return this.id; }

@Column
public String getText() { return this.text; }
}

@Entity
public class Something
{
@Id
public String getId() { return this.id; } }

@ManyToOne(fetch=FetchType.LAZY,optional=true)
@JoinColumnsOrFormulas({ @JoinColumnOrFormula(formula= @JoinFormula(value="(SELECT l.id from line_data l where text='something'", referencedColumnName="ID")) })
public LineData getLineData() { return lineData; }
}

If I do a query for Something and do a fetch() using criteria query,

root.fetch(Something_.lineData, JoinType.LEFT);

the result sql will contain a redundant formula in addition to a join.

Something like,

select something0_.ID as LINEID504_0_, linedata2_.ID as LINEID493_1_,
(SELECT l.id from line_data l where text='something') as formula23_0_
from something something0_
left outer join line_data linedata2_ on
(SELECT l.id from line_data l where text='something')=linedata2_.ID

When the formula is complicated, it brings a big impact to the query performance.

Environment: Hibernate 3.6.10
MS SQL Server 2008
Project: Hibernate ORM
Labels: hibernate jpa2 annotation
Priority: Major Major
Reporter: Quincy Leung
Original Estimate: 16h
Remaining Estimate: 16h
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