Nick Carag
,
Greenhorn
Dec 08, 2010 02:38:11
Hi all,
I've a problem with hibernate xml mapping and join. This is my scenario:
Table Resource
id, Pk
code
message
id_locale
Table Locale
id, Pk
code
description
On the table Resource I've a fk on id_locale referencing the column id of the table Locale.
Java Side, I've created a pojo ResourceBean with getter/setter for id, code, message, localeCode and this is my mapping
When i try to retrieve a resource, the join fails in finding the column ID_LOCALE
There's something wrong with the on clause but I don't know how to correct it in the mapping.
Thanks
Nick Carag
,
Greenhorn
Dec 09, 2010 01:25:39
Anyone? I just don't want to create a Locale POJO for a read only information like the locale code, and the use a one-to-one association. I found that with hibernate annotation @SecondaryTable it's possible to do what I'm asking for, but exists an xml equivalent?
Thanks
Arun Kumarr
,
Ranch Hand
Dec 09, 2010 02:01:15
It says so, because you're trying to join resource id (PK) with locale id_locale and id_locale is not present in locale table.
Please verify this example,
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-join
Nick Carag
,
Greenhorn
Dec 09, 2010 02:11:04
I think that my situation is similar to the one in the example
where PERSON is my RESOURCE and ADDRESS is my LOCALE, and in RESOURCE ther's ID_LOCALE that refers to ID of LOCALE or I'm wrong?
Arun Kumarr
,
Ranch Hand
Dec 09, 2010 02:19:37
PERSON is my RESOURCE and ADDRESS is my LOCALE, and in RESOURCE there's ID_LOCALE that refers to ID of LOCALE - Yes.
Nick Carag
,
Greenhorn
Dec 09, 2010 02:26:37
So base on this about key
It appears anywhere the parent mapping element defines a join to a new table that references the primary key of the original table
ther's no way to have
insted of
The only solution is to use a ono-to-one and create the Locale Pojo?
Arun Kumarr
,
Ranch Hand
Dec 09, 2010 02:32:01
Nick Carag
,
Greenhorn
Dec 09, 2010 02:40:19
First of all, thanks for your time.
I already try this but
- this needs an association table;
- this needs a POJO that maps the table Locale;
- this searches for a java.lang.String map
Just annoying...
Arun Kumarr
,
Ranch Hand
Dec 09, 2010 03:02:20
Ah! i overlooked when you mentioned locale pojo. I thought you'd mentioned about a link table pojo. My bad.
Did you try using the property-ref column used specifically for legacy.
http://docs.jboss.org/hibernate/core/3.5/reference/en/html/mapping.html#mapping-declaration-key
Nick Carag
,
Greenhorn
Dec 09, 2010 03:11:15
Yes i've tried with property-ref on key and foreign-key on join but nothing changes in the sql generated.
Nick Carag
,
Greenhorn
Dec 09, 2010 13:16:55
Finally I've mapped property localeCode as follow
But is it correct? Is there another way to achieve the same result?
Arun Kumarr
,
Ranch Hand
Dec 09, 2010 22:08:16
This would run a scalar sub-query. Though this would get your work done, I'm still worried why the join tags is not working.
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com