Or you give
Blaze-Persistence Entity Views a shot which handles all the DTO specifics for you.
If you map the "courseType" relation in the entity
Code:
@Entity
class Course{
@ManyToOne(optional = false)
@JoinColumn(name = "courseId")
CourseTypeInformation courseType;
// ...
}
.. the code with Blaze-Persistence Entity Views could look like this:
The DTO/Entity View definition
Code:
@EntityView(Course.class)
interface BasicData {
int getCourseId();
String getName();
@Mapping("courseType.streamId")
int getStreamId();
}
And the usage
Code:
CriteriaBuilderFactory cbf = //... see setup about how to create that
EntityViewManager evm = //... see setup about how to create that
// Your base query
CriteriaBuilder<Course> cb = cbf.create(entityManager, Course.class);
cb.where("courseId").eq(courseId)
.where("status").eq(status)
.where("courseType.status").eq(status);
// Applying projections independently
List<BasicData> data = evm.applySetting(EntityViewSetting.create(BasicData.class), cb);