I use in the Hibernate project. I read how to work with collections, but something is not clear:
There is information on how to work and what to write for the collection in the xml-file that describes the class. But what table should correspond to this class?

  1. For example, a class with three fields int id; int[][] и ArrayList<Person> persons; int id; int[][] и ArrayList<Person> persons; What should the table look like for such a class (no matter which database)? And if you can xml-file? I know about getters, setters and stand designs.

  2. And at the expense of my simple classes, I correctly understand - it is enough to create a label with the same fields as our class variables that we want to save, describe it, and continue to write functions in order to drag from the database and write?

  3. And another question, for example, I save in one class such ArrayList<Person> persons; - does this mean that in the Person class all the variables must also be Getters, Setters, and so on?

    1 answer 1

    As far as I understand, collections are convenient for communication between hotel classes (entities in the database), i.e. when @OneToMany and @ManyToMany annotations are written over the fields.

    For example, there is a table of cars and humans. Each person can be the owner of one car, and any car belongs to a single person. Then it is advisable to specify the collection field typed by a machine in the class of a person by writing the annotation @OneToMany above it.

    Therefore, if you want to store a collection (array for example) in one field of a table, then you probably need to write a separate class X, which will be serializable and add a field X to the class representing the essence of the database record. And Hibernate Entity Manager does the rest for you.

    • Thank you, as if everything is clear, but a piece of code would be clearer ... And what about objects such as Color, for example? If there is a piece of code share ... - JDev