Java DAO implementation setObjects -


there such problem. enter image description here

i have entity classes appartment, landlord etc. i'm creating apartmentdaoimpl, dao implementation apartment. clear primitive types, can landlordid.

the question - how set landlord field id?

this doesn't work because getid() method non-static:

apartment apartment = new apartment(id);             apartment.setrooms(rooms);             apartment.setdescription(description);             apartment.setfree(free);             apartment.setprice(price);             apartment.setlastupdatedprice(lastupdatedprice);             apartment.setlandlord(landlord.getid()); 

first, have decalre landlord object , set properties, e.g.:

landlord landlord = new landlord(); landlord.setname("foo"); landlord.setemail("foo@bar"); etc. 

alternatively, can db, if record exists:

landlord landlord = dataaccess.getlandlordbyname("heregoesthename"); 

of course, in latter case, need implement proper dataaccess class , access method dataaccess object.

only can assign apartment entity:

apartment.setlandlord(landlord); 

aside that, seems me don't grasp basic concepts of oop. nothing's wrong that, problem trying solve quite advanced one.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -