سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

you can use Hibernate or study droidpersistence library's source, (the lib is written for android though)

Use JPA. A popular implementation of JPA is Hibernate. There are plenty of tutorials to get you started.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top