这是代码:
Patient patient = factory.createPatient();
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(patient.getClass());
enhancer.setCallback(new DefaultMethodInterceptor(patient));
patient = (Patient) enhancer.create();
assertThat(patient.getFirstName()).isNotNull();
Enhancer enhancer2 = new Enhancer();
enhancer2.setSuperclass(patient.getClass());
enhancer2.setCallback(new DefaultMethodInterceptor(patient));
patient = (Patient) enhancer2.create();
assertThat(patient.getFirstName()).isNotNull();
它在最后一个断言上失败了
net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
...
Caused by: java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file my/package/entity/Patient$$EnhancerByCGLIB$$ca1e6685$$EnhancerByCGLIB$$f52743be
我问这个是因为我想增强 Hibernate 的实体,但有时它会自行返回已经增强的实体,而我的第二次增强失败。我怎样才能避免这种情况?