Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA with EclipseLink, error Entity cannot be cast to Entity, any help?

881879Aug 11 2011 — edited Aug 22 2011
Hello, I'm currently deploying a JPA project with EclipseLink on a MySQL db, it's been working fine, however, I'm receiving a problem of this type:

java.lang.ClassCastException: beans.Empleado cannot be cast to beans.Empleado

Where Empleado is my Entity, basically the problem happens here, where I store a result from a SQL select into a List and then assign the results into variables, it was working with no problems before, but now, everytime I run the code, the error shows up, and the only way to make it work at least 2 - 3 times, is restarting the Glassfish Server, here's the code:

Query q = em.createNamedQuery("Empleado.findByIdEmpleado");
q.setParameter("idEmpleado", 2);
List<Empleado> listaEmpleado = q.getResultList();
for(Empleado empleado1 : listaEmpleado){
testString = empleado1.getTecnologia();
}

But as I said, it was working fine before, so I don't think is actually a code problem, I guess the "cast" reference is happening here:

for(Empleado empleado1 : listaEmpleado)

The errors shows up with every function where I make this kind of casting......

As a comment, I have a similar project at home, and I don't have these problems, this is happening on a project at work, but both project are the same, it's just I'm doing this one at work and the other at home, which is working fine, thanks in advanced, have a nice day, I just hope I was clear about this!

Edited by: user3538005 on 08-11-2011 09:08 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 19 2011
Added on Aug 11 2011
5 comments
1,559 views