I will try to explain my problem clearly: I have two tables: document and category and they have a many-to-many relationship. I am learning to program in an elegant way in Java so please, excuse my ignorance if so.
I am doing a search on my database and I want to illustrate the same relationship between the retrieved element (a document) and its categories, when I create the objects from the resultSet.
I have created a Class Document and a Class Category; Do I need to add an ArrayList of Category as an attribute of Class Document? And an ArrayList of Document as attribute in Category?
I also need to do modifications on some Documents, do I need to create an attribute id in Class Document so store the id from the table in DB so that the update is easier?
My Class Document might look like:
public class Document {
private Integer id; // Id from DB, 0 if new object
private String name;
private String url;
private Date dateCreated;
private ArrayList<String> category;
// getters & setters...
}
This might be confusing but I just want to things in a "standard" way! I know how to do all this in a "dirty" way by using multiple queries etc... but once again I need idea from experienced OO developpers!
EDIT: I removed MVC; I am new in Java so I am just using the basic Java (No ORM, No framework). I don't know what Hibernate is, I am investigating.