File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes JPA Join Query to display a sectorname from a sectorID foreign key table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA Join Query to display a sectorname from a sectorID foreign key table" Watch "JPA Join Query to display a sectorname from a sectorID foreign key table" New topic
Author

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

Jay Tai
Ranch Hand

Joined: Apr 25, 2012
Posts: 162

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!



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