wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Simple JOIN in JPA proving difficult Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Simple JOIN in JPA proving difficult" Watch "Simple JOIN in JPA proving difficult" New topic
Author

Simple JOIN in JPA proving difficult

Rj Jones
Greenhorn

Joined: Mar 20, 2012
Posts: 3
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.
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
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

Joined: Mar 20, 2012
Posts: 3
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

Joined: Mar 17, 2012
Posts: 892
    
    9
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

Joined: Mar 20, 2012
Posts: 3
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

Joined: Mar 17, 2012
Posts: 892
    
    9
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.
 
 
subject: Simple JOIN in JPA proving difficult