Hibernate returns same entity from same request, but in one case it is proxied and in second case it is not. Why?

Viewed 261

Hibernate returns same entity from same request, but in one case it is proxied and in second case it is not. Why it is sometimes proxied and sometimes is not?

I have a hibernate query:

    String q = "From EntityCustomFields as ecf "
            + "left outer join fetch ecf.customFields "
            + "where ecf.fleetId=:fleetId and ecf.entityType=:et";

    Query query = s.createQuery(q);
    query.setInteger("fleetId", fleetId);
    query.setString("et", et.toString());
    EntityCustomFields res = (EntityCustomFields) query.uniqueResult();

in res variable I get a EntityCustomFields object.

First case: customFields property contains few members with type: CustomField_$$_jvste27_9f this looks like proxied object, but in request "fetch" used and as I understand hibernate should not proxy as uses eager fetch. Right?

In second case I use other value for et parameter and get customFields property members with type: CustomDDLField and this is not proxied!

It becomes even more strange as I know that same database entity in first case is proxied but in second case it is not.

One detail could be significant is the CustomDDLField extends CustomField

1 Answers
Related