aspose file tools*
The moose likes Object Relational Mapping and the fly likes JPA Entity Relationships Newbie Questions 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 Entity Relationships Newbie Questions" Watch "JPA Entity Relationships Newbie Questions" New topic
Author

JPA Entity Relationships Newbie Questions

Calvin Hughes
Greenhorn

Joined: Jul 24, 2011
Posts: 8

Hey guys,

This is my first post so I hope I am going about this the right way. I am working on my first JPA project ever so this may seem like some very basic questions but please bear with me.

My work has me putting together a database for all of the awards we have given out over the last 40 years to our faculty and students. My database structure looks kind of like the picture I have attached to this post. We have about 850 award instances of the 30 or so awards we give out each year. They have been given to about 500 different people and some people have received an award multiple times or multiple awards.

I understand that my Award Instances table has a many to one relationship with each of the other tables but how do I show that in my entities?? Do I treat my Awards Instances table as one big join table??

I've looked at lots of examples but all of them are usually just 2 tables. I'm not sure how to treat something more complex.

Thanks for any help you guys are willing to give!



[Thumbnail for Database Relationships.jpg]

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I don't really see the need for the Year Awarded entity. Why not just make a date field in "Instance of Award". By the way I don't really like that name. Also the name of the entity "Award Name" is weird. Why not name it Award with a field name?

Coding a ManyToOne relationship isn't that complicated. Could you show us your code (not all but only the relevant)?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Calvin Hughes
Greenhorn

Joined: Jul 24, 2011
Posts: 8

Yeah sorry the picture I posted was for brevity to show the general layout of the tables. Each table other than the year shows more detail and has a different naming scheme. To be honest I think I am over thinking things. I'm still studying up on how to use JPA and JPQL. Other than mapping out the relationships between tables in the entities, working with how the tables data all comes together should be in my queries right? wow I feel like that is a really dumb question.

I'll post some code when I actually have an example to show.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JPA Entity Relationships Newbie Questions