Je fais des tests sur un projet ejb3 en utilisant ejb3unit session bean test. Le test suivant échouera avec la dernière vérification assertNotSame()
.EJB3Unit save-function ne sauvegarde pas vraiment mon entité
public void testSave() {
Entity myEntity = new Entity();
myEntity.setName("name1");
myEntity = getBeanToTest().save(myEntity);
assertNotSame("id should be set", 0l, myEntity.getId());
// now the problem itself ...
int count = getBeanToTest().findAll().size();
assertNotSame("should find at least 1 entity", 0, count);
}
Alors, que se passe-t-il? La méthode save (entity) délivre mon objet "persisted" avec un id set. Mais quand je vais essayer de trouver l'objet en utilisant findAll()
il ne livrera pas un seul résultat. Comment puis-je obtenir ma méthode ServiceBean.save
pour que l'entité persistante puisse être trouvée?
Modifier
Mon ServiceBean ressemble à ceci
@Stateless
@Local(IMyServiceBean.class)
public class MyServiceBean implements IMyServiceBean {
@PersistenceContext(unitName = "appDataBase")
private EntityManager em;
public Entity save(Entity entity) {
em.merge(entity);
}
public List<Entity> findAll() {
... uses Query to find all Entities ..
}
}
et pour les ejb3unit ejb3unit.properties:
ejb3unit_jndi.1.isSessionBean=false
ejb3unit_jndi.1.jndiName=project/MyServiceBean/local
ejb3unit_jndi.1.className=de.prj.MyServiceBean
peut-il y avoir un problème en utilisant: @PersistenceContext (unitName = "appDataBase")? – justastefan
plutôt pas. avez-vous vérifié si vous avez une transaction en cours? – Bozho