May 2015
Intermediate to advanced
234 pages
4h 18m
English
In this recipe, we will add a DAO method to generate, from an SQL query joining several tables, a list of objects with their dependencies. We will retrieve a list of User objects along with their Post objects (blog posts written by these users).
You need to have model classes related to each other. In this example, a user has many posts:
public class User {
private Long id;
private String firstName;
private Integer age;
private LinkedList<Post> posts = new LinkedList<Post>();
public class Post {
private long id;
private String title;
private Date date;
private User user;You need to have corresponding database tables, for example:
CREATE TABLE `user` ( `id` int(11) AUTO_INCREMENT, `first_name` ...
Read now
Unlock full access