onBeforeDetach() logic


I have this entity ComandaClient with associated entities Client, Model and Planificari. I want to set transient field “statusTermen” for ComandaClient depending on Planificari when the entity is loaded

public void onBeforeDetach(ComandaClient entity, EntityManager entityManager) {


public PlanificareTip getStatusPlanificare(ComandaClient entity) {

    if (entity.getPlanificari() == null) return PlanificareTip.livrare;

    List<Planificare> planificari = entity.getPlanificari();
    for (Planificare myPlanificare : planificari) {

        Date currentDate = new Date();
        if (myPlanificare.getDataInceput().getTime() > currentDate.getTime()) {
            return myPlanificare.getTip();

    return PlanificareTip.livrare;

my statusPlanificare field is set correctly but ComandaClient entity looses connection to its associated entityes Client and Model …

How do I keep the associated entityes “attached” to this detached entity?

Thank you

Hi George,

Add the planificari attribute to the view which is used to load the entity.
We’ll try to simplify this case in the future, see the issue.