design - A class modeling a M:N relationship in Java: remember instances or just primary keys? -


i have class lease modeling relationship between classes customer , videogame. pretty simple , straightforward; looks this:

class lease() {     private videogame videogame;     private customer customer;     // etc.     public lease(videogame videogame, customer customer) {         this.videogame = videogame;         this.customer = customer;     } } 

each of 3 classes represented database table autogenerated index , additionaly leases table has foreign key reference both customer , videogame.

while retrieving lease database, should i...

  1. proceed retrieve both videogame , lease instances in getlease(long id) method, , store objects in lease instance
  2. or, better lease class remember "foreign keys" , should retrieve instance of customer , videogame when needed? require lease class change to

    class lease() { long videogame; long customer; // etc. }

the first approach seems more natural, i'm looking "best practices" kind of advice on this. thank you!

if using orm framework (hibernate, jpa etc) should create classes relationship want, i.e. typically using class-to-class relationship. framwork responsible on creating queries , saving primary keys in db tables.

if not use framework convert keys objects , how create model, using objects in model more natural.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -