I have a problem to get a Single Location Object from a List. Calling getLocations() in primefaces dataTable works. And I can display all Locations. But when I want to get a Single Location from the locations List, then I get always a ClassCastException. I use JPA (Hibernate).
Entity Bean:
@Entity
@Table(name = "location")
@NamedQueries({
@NamedQuery(name = "Location.findAll", query = "SELECT l FROM Location l")})
public class Location implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name = "name")
private String name;
...
CDI Bean:
private List<Location> locations = null;
@PostConstruct
public void init() {
locations = getService().findAll();
Iterator iter = getLocations().iterator();
Location first = (Location)iter.next(); //ClassCastException
Same problem with this:
for (Location location : getLocations()) //Classcastexception
{...}
error Message:
java.lang.ClassCastException: package.ejb.entity.Location cannot be cast to package.ejb.entity.Location
Aucun commentaire:
Enregistrer un commentaire