0
votes

We used to have a EAR that included an EJB jar and a WAR. From the EJB we sent a dto class to the WAR. Everything was fine.

Now we have tried to extract the WAR from the EAR and created a EJB-client (API jar) that the WAR uses. This API jar includes the dto class that we send from the EJB to the WAR. In the EAR the API is deployed in the lib directory.
In the WAR we have the same API jar in WEB-INF/lib directory.
But now we get a ClassCastException when accessing the internals of the dto class.

The method call to the EJB goes ok and we can assign the resulting List in the WAR. But when we try to read a value from the DTO class we get ClassCastException.
We have checked over and over again so the API jar is not imported twice somewhere in the EAR or the WAR. But now we are at the brink of giving up.

Anybody have any idea what we are doing wrong?

1
Ok, so I got the class names and they are the same, just like we have seen while debugging... This is the Exception that we get. Error: : java.lang.ClassCastException: com.xxx.admintool2.service.dataroaming.dto.LegalEntityDTO cannot be cast to com.xxx.admintool2.service.dataroaming.dto.LegalEntityDTOPierre

1 Answers

0
votes

"When we try to read a value from the DTO class we get ClassCastException"

Just get/read it as an object say obj, and then print its type in your
logs or on the console (log it before you get the exception of course)
Something like this should help: obj.getClass().getName().
Then review your code and see: 1) what you're casting it to in your code
or 2) to variables of what types you're assigning it in your code.
This (plus the stack trace which you probably have) should help
you identify why you're getting this exception.