Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate join and key tag

 
Nick Carag
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this
 
Nick Carag
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i've tried with property-ref on key and foreign-key on join but nothing changes in the sql generated.
 
Nick Carag
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic