Links

About

Loading Lists

MentaBean allows you to quickly and easily load a list of beans without SQL. The way it works is that you use a bean instance to specify the properties you want to include in the WHERE clause of the generated SQL. For example, to load all 18 year-old men you would do something like this:

NOTE: The properties are appended to the WHERE clause with the AND operator.

To load all posts from a certain user, you would do something like this:

User user = ... ; // the user object from whom you want the posts...
Post p = new Post();
p.setUser(user); // the post only cares for the id of the user and that's what it will use in the WHERE clause
List<Post> posts = session.loadList(p);
System.out.println("User " + user.getUsername() + " has " + posts.size() + " posts!");

Keep in mind that eventually you will need to build the SQL yourself to load a list. For example, if you want to load all users between 18 and 25 years old, there is no way to use a bean instance to specify this condition. So you would do something like this: