Ids must exist in the Container or as a generated column, missing id:nombre

[font=Times New Roman]

Hello, I am Peruvian and I have a problem, I get a problem in my application “Ids must exist in the Container or as a generated column, missing id: nombrecargo”, and hope you can help me, thanks.

CargoU cargos =new CargoU();
@SuppressWarnings(“static-access”)
List s = cargos.getListaCargo();

    final BeanItemContainer<Cargo> bic = new BeanItemContainer<Cargo>(Cargo.class);
            
           for (Cargo c : s) {
                bic.addBean(c);
                
           }
                        					
           setContainerDataSource(bic);              
           setVisibleColumns(new Object[]{"id","nombrecargo"});              
           setColumnHeaders(new String[]{"Código","Nombre de Cargo"});
		
		setSelectable(true);
        setImmediate(true);		
        setSizeFull();

//AQUI LA ENTIDAD Cargo

public class Cargo implements Serializable{

@PrimaryKey
@Persistent (valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;

@Persistent
private String nombrecargo;

public Cargo(final String nombrecargo){
	this.nombrecargo=nombrecargo;
}

public String getNombreCargo(){
	return nombrecargo;
}
public void setNombreCargo(final String nombrecargo){
	this.nombrecargo=nombrecargo;
}

public Long getId(){
	return id;
}

}

//EL LLAMADO DEL DAO CargoU
public class CargoU {
public final static List getListaCargo(){
final PersistenceManager persistencia=PMF.get().getPersistenceManager();
final Query consulta = persistencia.newQuery(Cargo.class);

	try{
					
		return (List<Cargo>) consulta.execute();
	}
	finally{
		persistencia.close();
	}
}

}

[/font]

¡Hola Luis!
The way the MethodProperty that BeanItem uses works, is that it looks at the names of the getters/setters to determine the name of the property. In your case, your getter is named getNombreCargo, which would give you a propertyId of “nombreCargo”, not “nombrecargo”