There is such problem.
I have some entity classes Appartment
, Landlord
etc. Now I'm creating ApartmentDaoImpl
, that is DAO implementation for Apartment
. Everything is clear with primitive types, I can get landlordId
.
The question is - how to set Landlord
field by his id
?
This doesn't work because getId()
method is 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, you have to decalre Landlord Object and set its properties, e.g.:
Alternatively, you can get it from DB, if the record already exists:
Of course, in the latter case, you need to implement a proper DataAccess class and access its method by
dataAccess
Object.Only then you can assign it to the Apartment Entity:
Aside from that, it seems to me that you don't really grasp basic concepts of OOP. Nothing's wrong with that, but the problem you are trying solve is quite an advanced one.