partial « Fetch « JPA Q&A

1. Hibernate noob - retrieve partial object

Greetings! I have the following class and at times need to retrieve only title and subTitle elements:

public class Article implements Serializable {

    private static final long serialVersionUID;

2. May I retrieve partial columns (properties) only?

If you use different classes for each "bit" of the table, then yes. You can't partially load objects, but you can break up tables into multiple classes. Hibernate will handle them correctly. I do this from time to time. My approach is to put the "important" fields into the main class, then use one-to-ones to other classes that are mapped to ...

3. Hibernate partial collection fetching

Hi I have classes: Course and Student. The relation between them is many to many. How can I fetch only specified part of Students collection of Course class (eg. student.firstName = "Bob") using Criteria (not hql) in one database call. Can Hibernate assign those students to Course.students without any additional coding? I've tried setResultTransformer() method, but then I would have to ...