我正在尝试将 DTO 映射到其对应的 Hibernate 实体。我从 Hibernate 会话加载实体并立即执行映射。
这是我得到的例外:
javassist.NotFoundException: my.pkg.MyEntity$$EnhancerByCGLIB$$a7950497
at javassist.ClassPool.get(ClassPool.java:436)
at ma.glasnost.orika.impl.generator.JavassistCompilerStrategy.assureTypeIsAccessible(JavassistCompilerStrategy.java:181)
at ma.glasnost.orika.impl.generator.MapperGenerator.build(MapperGenerator.java:56)
at ma.glasnost.orika.impl.DefaultMapperFactory.buildMapper(DefaultMapperFactory.java:1057)
at ma.glasnost.orika.impl.DefaultMapperFactory.lookupMapper(DefaultMapperFactory.java:599)
at ma.glasnost.orika.impl.DefaultMapperFactory.lookupMapper(DefaultMapperFactory.java:566)
at ma.glasnost.orika.impl.MapperFacadeImpl.resolveMapper(MapperFacadeImpl.java:516)
at ma.glasnost.orika.impl.MapperFacadeImpl.resolveMappingStrategy(MapperFacadeImpl.java:199)
at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:337)
at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:357)
at ma.glasnost.orika.impl.ConfigurableMapper.map(ConfigurableMapper.java:148)
这是在我的工厂构建器上配置的 HibernateUnenhanceStrategy,这就是我的 Mapper 的样子:
public class MyMapper extends ConfigurableMapper
{
@Override
protected void configureFactoryBuilder(DefaultMapperFactory.Builder factoryBuilder)
{
factoryBuilder.compilerStrategy(new JavassistCompilerStrategy());
factoryBuilder.unenhanceStrategy(new HibernateUnenhanceStrategy());
}
@Override
protected void configure(MapperFactory factory)
{
factory.classMap(MyEntity.class, MyDTO.class);
}
}
我现在的解决方法是在从会话加载和使用 Orika 映射之间自行取消对实体的增强,但我真的不想这么明确。我怎样才能得到这个工作?