EntityManager.contains unsupport Entity enhanced by CGLIB

Description

invoke contains() method with a entity enhanced by CGLIB while throw IllegalArgumentException.
other methods like persit() remove() can config the hibernate interceptor by override the getEntityName().

public class UnByteCodeProxyInterceptor extends EmptyInterceptor {
private static final long serialVersionUID = -6422637558312349795L;

@Override
public String getEntityName(Object object) {
if (object != null) {
Class<?> cl = object.getClass();
if (ProxyBeanUtils.isProxy(cl)) {
cl = cl.getSuperclass();
}
return cl.getName();
}
else {
return null;
}
}

}

but the contains() not invoke the entityNameResolver to get Entity name.

statement in org.hibernate.ejb.AbstractEntityManagerImpl.contains()

getSession().getSessionFactory().getClassMetadata( entity.getClass() )

change to

getSession().getSessionFactory().getClassMetadata( ((SessionImplementor)getSession()).bestGuessEntityName(entity) )

can workaround this problem.

Environment

None

Assignee

Unassigned

Reporter

v

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

Yes, likely

Pull Request

None

backportDecision

None

backportReEvaluate

None

Affects versions

Priority

Major
Configure