This code is from an entity bean generated in netbeans. In the last
for loop the code is broken. Anyone have any idea what it should be
doing, or better yet how I should approach fixing it?
/**
* Persist the given entity.
*
* @param entity the entity to persist
*/
protected void createEntity(People entity) {
EntityManager em =
PersistenceService.getInstance().getEntityManager();
em.persist(entity);
for (People value : entity.getPeopleCollection()) {
value.getPeopleCollection().add(entity);
}
for (People value : entity.getPeopleCollection1()) {
value.getPeopleCollection().add(entity);
}
for (Mylocation value : entity.getMylocationCollection()) {
value.getPeopleCollection().add(entity);
}
for (Mylocation value : entity.getMylocationCollection1()) {
People oldEntity = value.getPeopleCollection(); //
attempts to assign a collection to a single entity
value.setPeopleCollection(entity); // here it's trying
to assign a single entity where a collection is expected
if (oldEntity != null) {
oldEntity.getMylocationCollection1().remove(entity);
}
}
}