Forums Register Login

Hibernate join and key tag

+Pie Number of slices to send: Send
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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
PERSON is my RESOURCE and ADDRESS is my LOCALE, and in RESOURCE there's ID_LOCALE that refers to ID of LOCALE - Yes.
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Check this
+Pie Number of slices to send: Send
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...
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Yes i've tried with property-ref on key and foreign-key on join but nothing changes in the sql generated.
+Pie Number of slices to send: Send
Finally I've mapped property localeCode as follow

But is it correct? Is there another way to achieve the same result?
+Pie Number of slices to send: Send
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


reply
reply
This thread has been viewed 7681 times.
Similar Threads
Incorrect joins on composite ID
Joining tables
Getting unrequested nested query
Hibernate generating queries with duplicate columns
joined-subclass problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:31:52.