| When mapping a mandatory component to an Entity class it is a good practice to initialize it in the Entity constructor and make it _final _like following:
@Valid
private final MyComp myComp= new MyComp(MyEnum.A);
public MyComp getMyComp()
{
return this.myComp;
}
In this case we must map it using field access Strategy: access="field". The Problem: Hibernate will create a new instance by reflection, which is not necessary for performance reasons and it will also loose optional arguments in the component construction. The component also needs a boilerplate empty constructor in this case. Feature: A new access strategy access="field-final" will not create a new instance and just reuse the existing one. The <parent> mapping can easily be solved by adding this to the component constructor. |