I'm new to vaadin, I'm trying to implement EclipseLink with vaadin, in my project i'm trying to get list of states from db using eclipselink and i'm getting the result set in my main file but when trying to add this items into a table using for each loop i'm getting a strange error
com.vaadin.server.ServiceException: java.lang.ClassCastException: com.example.dao.States cannot be cast to com.example.dao.States.
PFB code snippets
Main Java File:
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = VaadintestUI.class)
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
final String PERSISTENCE_UNIT_NAME = "com.test.jpa";
EntityManagerFactory factory;
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
Query q = em.createQuery("select s from States s");
List<States> stateList = q.getResultList();
System.out.println("Size: " + stateList.size());
Table table = new Table("The US States");
table.addContainerProperty("Name", String.class, null);
table.addContainerProperty("Population", Integer.class, null);
for (int i = 0; i < stateList.size(); i++)
{
table.addItem(new Object[]{ stateList.get(i).getState(),stateList.get(i).getPopulation()},i);
}
table.setPageLength(table.size());
layout.addComponent(table);
}
}
Persitence.xml
<persistence-unit name="com.test.jpa" transaction-type="RESOURCE_LOCAL">
<class>com.example.dao.States</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/testdb" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="root" />
</properties>
</persistence-unit>
States.java
@Entity
public class States {
@Id
private Long id;
private String state;
private String population;
//Setters and getters//
Stack trace Caused By: java.lang.ClassCastException: com.example.dao.States cannot be cast to com.example.dao.States at com.example.vaadintest.VaadintestUI.init(VaadintestUI.java:69) at com.vaadin.ui.UI.doInit(UI.java:645) at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:222) at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74) at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)