Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Vaadin 7.4.6 + Glassfish 4.1 + JavaEE 7 + JPAContainer
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 <class>com.felixovelar.notificadorcumpleanhos.entities.Empleados</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
This is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="com.felixovelar_NotificadorCumpleanhos_v5_war_1.0PU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/CumplePool</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties/>
</persistence-unit>
</persistence>
This 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<Empleados> listaEmpleados = (List<Empleados>)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
Hi,
My pro tip is to keep away of JPAContainer. I really no more find a real case where it would be the perfect choice. Sorry this comes one week late, it has been super busy week for me.
Instead of JPAContainer you can just fetch the list of entities from your backend and list them in components for example with BeanItemContainer. Or if you face memory/performance issues with really big tables you could look at ListContainer in Viritin or its "lazy loading" extensions (see e.g. this example).
cheers,
matti