While you could implement your own mapper, Hibernate (and the other JPA implementations) will solve your problem quite thoroughly out of the box. If properly configured, loading records from Table1
will automatically materialise your @OneToMany
relationship with Table2
java - map database tables into class
Pregunta
When retrieving data from the database in Java, how can I get a instance of an class for each database row dynamically?
Example: I've got two tables (Table1: id, name, Table2: id, name, age) and two classes with the same properties. For every row in Table1 I want an List-item (or something related) for this row.
Is there a class/default method to do this in Java?
Solución
Otros consejos
you can use Hibernate
or study droidpersistence library's source, (the lib is written for android though)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow