I have a "Folder" class, that has many files, just like below
class Folder {
...
@ManyToMany
private Set<File> files= new HashSet<>();
}
I need to save not only the files that a folder has, but also the order of that file for that folder (it can be different for others). If I have 3 files: "X Y Z", I also need to know that:
X = 1st
Y = 2nd
Z = 3rd
Now that you understood the problem, there is something more. The files have types.
class File {
...
@ManyToOne
private FileType type;
}
Each type of file will generate a different ordering on the Folder.
So, I can have a folder with 4 files:
"X", type "jpeg"
"Y", type "jpeg"
"Z", type "png"
"W", type "png"
In this case, it should be
For type jpeg, X = 1st, Y = 2nd
For type png, Z = 1st, W = 2nd
I am not sure what is the best way to do this.
- Should I create another class that will hold the relation? I would still have a problem to differentiate filetypes.
- Should I create a Map<FileType, FileWithOrder> so I can separate each filetype and then give them an integer with their order number?
- Other better sugestion? :)
I hope I was clear enough on my problem. Thanks