0

When mapping from a DTO to a hibernate entity I get following exception:

ma.glasnost.orika.MappingException: ma.glasnost.orika.impl.generator.CompilerStrategy$SourceCodeGenerationException: class com.exmaple.MyEntity_$$_jvst402_4 is not accessible

The entity is public.

Versions:

  • spring-boot-starter-data-jpa: 1.4.0.RELEASE
  • orika: 1.4.6
  • hibernate: 5.0.9.Final.
Ben George
  • 887
  • 3
  • 11
  • 22
  • Any private fields within Entity? If yes, have you added getters and setters for them? –  Sep 20 '16 at 22:32
  • No private fields. It is failing at classPool.get(className). It is as if javassist does not know about the class. I have seen this work before with hibernate + spring + orika without effort. – Ben George Sep 20 '16 at 22:56
  • Ok, any inner classes then? The dollar sign in your entity suggests there is an inner class that couldn't be accessed. –  Sep 20 '16 at 23:03
  • I thought it indicated the proxy object that hibernate created ? – Ben George Sep 20 '16 at 23:08
  • Is your entity class auto generated using Javaassist? May be it generates the entity with an inner class? –  Sep 20 '16 at 23:11
  • My class is 'hand written'. When I call mySpringDataJpaRepository.findOne(id) it returns the MyEntity _$$_jvst class. – Ben George Sep 20 '16 at 23:18
  • Please see if this post helps http://stackoverflow.com/questions/2216547/converting-hibernate-proxy-to-real-object May be you should extract the real Entity object from Hibernate Proxy before transformation. –  Sep 20 '16 at 23:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/123820/discussion-between-ben-george-and-programmer). – Ben George Sep 20 '16 at 23:25

1 Answers1

0

This error can occur when the mapping is not configured correctly. The error can be very very misleading.

Configuration that caused the error:

factory.classMap(MyEntity.class, MyEntity.class).byDefault().register();

The fix

factory.classMap(MyEntity.class, MyEntityDTO.class).byDefault().register();

I considered deleting this question as it is not an issue with any of the libraries but essentially a typo/copypasto in my mapping configuration. However for reasons best described by XKCD I shall let it remain.

Ben George
  • 887
  • 3
  • 11
  • 22