Can someone please explain the best way to solve this problem.Suppose I have three classesPersonVenueVehicleI have a DAO method that needs to return some or all of these attributes from each of the classes after doing a query.Please note, by requirements I am using one DAO for all three classes and no frameworks.Only my own MVC implementationHow do I accomplish this? It seems very wrong to make a class PersonVenueVehicle and return that as an object to get the instance field, values.I was taught that the database entities must be reflected by classes, if this is case how is it implemented in such a situation?
java classes and database queries
java;object oriented;database;java ee;dao
Start with methods that run a specific query and return just the data that you need, as opposed to a more complex method that can return many combinations of data.I'm guessing there's some kind of relationship between the classes you mentioned, such as that a Person has one or more Vehicles, and maybe they commonly travel to one or more Venues, so model your classes to reflect those relationships. In this example, your Person object would contain a List<Vehicle> and a List<Venue>.So if you need to retrieve one Person and all their associated data, create a DAO method to return a single Person object with its collections loaded.If you just want the Person with their Vehicles, create a DAO method to return a Person object with their List<Vehicle> loaded and their List<Venue> null.If you want a list of Persons, and you don't immediately need their Vehicles or Venues, return a List<Person> with null collections.