[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5041) @ManyToOne not working with @Formula
Sharath Reddy (JIRA)
noreply at atlassian.com
Tue Apr 27 16:31:36 EDT 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5041?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=36729#action_36729 ]
Sharath Reddy commented on HHH-5041:
------------------------------------
You should be posting this in the forums first. Check if this works for you:
@Entity
@Table(name="product")
public class Product
{
@Id
public Integer id;
@Column(name="product_idnf", length=18, nullable=false, unique=true,
columnDefinition="char(18)")
public String productIdnf;
@Column(name="description", nullable=false)
public String description;
@ManyToOne
@JoinColumnsOrFormulas(
{
@JoinColumnOrFormula(formula=@JoinFormula(value="SUBSTR(product_idnf, 1, 3)",
referencedColumnName="product_idnf"))
})
@Fetch(FetchMode.JOIN)
private Product productFamily;
public Product getProductFamily()
{
return productFamily;
}
}
Hibernate generates the following SQL:
select
product0_.id as id9_1_,
product0_.description as descript2_9_1_,
product0_.product_idnf as product3_9_1_,
SUBSTR(product0_.product_idnf,
1,
3) as formula13_1_,
product1_.id as id9_0_,
product1_.description as descript2_9_0_,
product1_.product_idnf as product3_9_0_,
SUBSTR(product1_.product_idnf,
1,
3) as formula13_0_
from
product product0_
left outer join
product product1_
on SUBSTR(product0_.product_idnf,
1,
3)=product1_.id
where
product0_.id=?
The test case still fails for me - I am testing against HSQL database, and invoking the SUBSTR function within the join condition does not seem to work, but MAY work with your database...which one are you using?
I get the error:
01:40:47,246 WARN JDBCExceptionReporter:100 - SQL Error: -64, SQLState: 37000
01:40:47,247 ERROR JDBCExceptionReporter:101 - not allowed in OUTER JOIN condition
> @ManyToOne not working with @Formula
> ------------------------------------
>
> Key: HHH-5041
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5041
> Project: Hibernate Core
> Issue Type: Bug
> Components: annotations
> Affects Versions: 3.5.0-CR-2
> Reporter: Chris Wilson
> Attachments: HibernateAnnotationJoinOnFormulaTest.java
>
>
> HHH-4382 was marked as resolved fixed in 3.5. However, I cannot find the fix, and it appears still to be broken for me.
> The attached test case fails with 3.5.0-CR-2 just as it did with 3.3.2. It seems to ignore the @Formula annotation and simply create a productFamily column, which is of course empty.
> If I am doing something wrong, please could you tell me what it is, so that I can fix my code?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list