This sounds ridiculous I know, but I don't design the schemas here, our enlightened data architects do.
On one table I have an integer column which, if we had RI, would be referencing another table which has a pk char column:
Code:
<class name="table1">
<key column="pk_column"..../>
.....
<many-to-one class="table2" column="int_column" ..../>
</class>
<class name="table2">
<key column="string_column"..../>
.....
</class>
The following statement will join the two tables successfully:Code:
SELECT
table1.AField,
table2.BField
FROM
table1,
table2
WHERE
substr(digits(table1.int_column),4,7)=table2.string_column
Hibernate produces the following:Code:
Select
......
inner join
table2 table2_
on substr(digits(this_.int_column),4,7)=table2_.string_column
.....
Which of course results in an error.
It seems hibernate gives you little control over the sql that is produced on the many-to-one joins. I've poked around the API, but extending the ManyToOne.class would be extremely complex. Hibernate will let me run scalar functions in HQL, but I fail to see how those would help me load objects into another object. The unfortunate alternative is results to a situation where I have to do n(n+1) selects from the database to retrieve the required data.
I'm not asking for support built into hibernate, because, trust me, I know this situation is ridiculous. What I'm asking is for a little advice or direction to get me out of this hole. Thank you.