Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA Join Query to display a sectorname from a sectorID foreign key table

 
Jay Tai
Ranch Hand
Posts: 221
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My application shows a list oof projects which should include the name of the sector and the name of the country for each project. I"m using Netbeans 7.3 and automatically generating the JPA classes. The list in the JSF page shows projects, description, the sector ID (foreign key), country ID (foreign key). Instead of showing the numeric ID values, I would like the list to show the corresponding string values of the foreign keys (ie: instead of showing sector ID, I"d lik to show sectorname corresponding to the ID).


I try to modify the NamedQuery field in the entity class of the projects table from:



to:





I then create a property for the sectorname (below the sectorID) and write the getters and setters for the sector name. I add the sectorname title in the JSF page and get the following error:





I'm really not sure how to correctly create a JOIN query so that the string are pulled in the project list from the foreign key tables (sector and country). Would apprecoate any advice. I've included the main classes of the app. Please let me know if i need to cut down or add any information. Thanks in advance!



 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic