Hello,
I’m starting to test this framework and I can’t get data from my JPA Entities into a Table or even print the elements onto the console.
I get this error on Glassfish log.
Grave: java.lang.IllegalArgumentException: No [EntityType]
was found for the key class [com.felixovelar.notificadorcumpleanhos.entities.Empleados]
in the Metamodel - please verify that the [Entity]
class was referenced in persistence.xml using a specific com.felixovelar.notificadorcumpleanhos.entities.Empleados property or a global false element.
This is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?> org.eclipse.persistence.jpa.PersistenceProvider jdbc/CumplePool falseThis is my code:
@Theme(“mytheme”)
@Widgetset(“com.felixovelar.notificadorcumpleanhos.MyAppWidgetset”)
public class EmpleadosUI extends UI {
@Override
protected void init(VaadinRequest request) {
VerticalLayout content = new VerticalLayout();
content.setSizeFull();
setContent(content);
content.addComponent(new Label("Empleados"));
HorizontalLayout horizontalLayout = new HorizontalLayout();
horizontalLayout.setSizeFull();
EntityManager em = JPAContainerFactory.createEntityManagerForPersistenceUnit("com.felixovelar_NotificadorCumpleanhos_v5_war_1.0PU");
if (em != null) {
System.out.println("******* NO ES NULL!!!");
if (em.isOpen()) {
System.out.println("******* esta abierto el EM");
JPAContainer<Empleados> empleados = JPAContainerFactory.make(Empleados.class, em);
System.out.println("*****+++++ Elementos en Contenedor="+empleados.size());
Table tabla = new Table("Lista de Empleados", empleados);
tabla.setSizeFull();
horizontalLayout.addComponent(tabla);
horizontalLayout.setExpandRatio(tabla, 1);
}
} else {
System.err.println("******* Es null :(");
}
System.out.println("****** fin");
content.addComponent(horizontalLayout);
content.setExpandRatio(horizontalLayout, 1);
}
@WebServlet(urlPatterns = "/*", name = "EmpleadosUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = EmpleadosUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
If I instead of using Table try to print the elements whith this code:
EntityManager em = JPAContainerFactory.createEntityManagerForPersistenceUnit(“com.felixovelar_NotificadorCumpleanhos_v5_war_1.0PU”);
if (em != null) {
System.out.println(“******* NO ES NULL!!!”);
if (em.isOpen()) {
System.out.println(“******* esta abierto el EM”);
List listaEmpleados = (List)em.createNamedQuery(“Empleados.findAll”, Empleados.class).getResultList();
System.out.println(“====******==== CantidadEmpleados=”+listaEmpleados.size());
for (Empleados empleado : listaEmpleados) {
System.out.println("======+++++++ Empleado: " + empleado);
}
}
} else {
System.err.println("******* Es null :(");
}
I get this error in the logs:
It’s an error trying to cast Empleados (Employee Entity) to Empleados!!
Información: ******* NO ES NULL!!!
Información: ******* esta abierto el EM
Grave: java.lang.ClassCastException: com.felixovelar.notificadorcumpleanhos.entities.Empleados cannot be cast to com.felixovelar.notificadorcumpleanhos.entities.Empleados
at com.felixovelar.notificadorcumpleanhos.EmpleadosUI.init(EmpleadosUI.java:65)
at com.vaadin.ui.UI.doInit(UI.java:646)
…
… a very long stack trace…
…
Información: ====******==== CantidadEmpleados=9
(It prints the Size of the List. So I assume the data it’s there.)
I don’t know what I’m doing wrong. Maybe just missing something.
Will appreciate any help from you guys.
Thanks.
Félix