-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Joining on different data type columns. Please stop laughing
PostPosted: Thu Jun 25, 2009 10:06 am 
Newbie

Joined: Thu Oct 09, 2008 12:51 pm
Posts: 7
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.