0

I am using orika-core-1.5.4.jar in my Liferay 7.3.5 CE GA6 Portlet in order to map some classes. Everything goes well if I test it in a main method or if it is the first time when the portlet is deployed, but goes awry if I redeploy it - eg. when I make some changes and then deploy them. The error is the following:

 java.lang.ClassCastException: ma.glasnost.orika.generated.Orika_MedicForm_FormDTO_Mapper850365342121300$0 cannot be cast to ma.glasnost.orika.impl.GeneratedObjectBase

From what I have read (here is an interesting article and also this stack article), this is because the first time, the class was generated with a AppClassLoader and the second time with RestartClassLoader - the articles refers to Spring applications. But I am not clear how to manage this. Now, I have to restart the server each time in order to avoid this.

Any ideas would help, thanks !

Victor
  • 1,001
  • 2
  • 14
  • 25
  • 1
    If your code or orika library has any static variable you can have problem because the classloader of the OSGI modules are different in each module startup, so if you store a static reference, after the module restart, that class will belong to the old classloader, causing a ClassCastException in case you use it. So review your code and avoid using static variable and also review the orika library to double check if it is osgi-friendly. – jorgediaz-lr Nov 23 '20 at 06:55
  • @jorgediaz-lr I'll give it a try and come back with updates. Thanks ! – Victor Nov 23 '20 at 08:08
  • Unfortunately it doesn't seem to respond to this change - I made it non static and also made it at method scope (not class scope), but still returns the same exception on restart. – Victor Nov 23 '20 at 13:38

0 Answers0