• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Simple JOIN in JPA proving difficult

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Obviosuly a bit new to Hibernate, but I'm struggling if it is possible to do a simple JOIN in JPA/Hibernate ....

I have 2 tables. GAME table and GAME_DESCRIPTION TABLE for example..



I want to map an Entity that contains all the columns of the GAMES table plus the game description from game_description table (so I want to join on the GAME_DESCRIPTION_ID columns from both tables). I tried to map directly to a String ...



But I got a Entity not found java.lang.String error.

So, I then created a GAME_DESCRIPTION entity and tried joining the entities as follows : -



Now I am getting a "Repeated column in mapping for entity: com.sportech.support.jobs.model.sa.Game column: GAME_ID (should be mapped with insert="false" update="false")" error

Any ideas? Many thanks in advance.
 
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your @Id column mapping in the Game entity doesn't look right.
You have put column name as GAME_DESCRIPTION_ID when I think it should have been GAME_ID.
 
Rj Jones
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks for reply E Armitage.

Think it was a bit of a typo sorry, but still getting the same error .....




Also here is the GameDetails entity ....




Reminder of the error message - Repeated column in mapping for entity: Game column: GAME_DESCRIPTION_ID (should be mapped with insert="false" update="false")
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remove the descriptionNo and associated mapping

JPA takes away the need to use Ids in your code. Think objects. You already have the GameDetails object in Game so you get the descriptionNo through that object.
 
Rj Jones
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great reply thanks E Armitage

I think (perhaps wrongly) i was thinking more in terms of SQL than object and entities.

I need to search from the GAMES table with the GAME_DESCRIPTION_ID within a certain range (say 1-5). I have added a criteria for this search, but I would have thought the GAME entity requires the descriptionNo to run the search or is JPA clever enough to realize the mappings?
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes JPA will handle it fine.

In this case your query will be something like

assuming fetch type eager. Again here it's all about objects.
reply
    Bookmark Topic Watch Topic
  • New Topic