Reputation: 1
I have Category and PaCategory
public class Category implements Serializable {
private int categoryId;
private int paCategoryId;
private String name;
private PaCategory paCategory;
public Category() {
}
//getter and setter
}
public class PaCategory implements Serializable {
private int paCategoryId;
private String pname;
public PaCategory() {
}
//getter and setter
}
Main
List<Category> categories = JDBIConnector.get().withHandle(handle -> {
return handle.createQuery("SELECT c.category_id,c.name,pa.pa_category_id,pa.name pname FROM category c join pa_category pa on pa.pa_category_id =c.pa_category_id WHERE category_id=2").mapToBean(Category.class).list();
});
System.out.println(categories);
paCategory is null
[Category{categoryId=2, paCategoryId=1, name='Gia dụng', paCategory=null}]
But I would like a PaCategory and its value.
Upvotes: 0
Views: 444
Reputation: 293
You will need @Nested annotation for PaCategory
@Nested
private PaCategory paCategory;
Upvotes: 1