Aide pour une requete avec pattern JpaDao
Bonjour.
J'utilise le pattern JpaDao dans mon application et j'ai voulu faire une requête assez simple qui est la suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| @Transactional(readOnly = true)
public boolean isEmailExist(String email) {
String selectClause = "SELECT count(d.id) ";
String fromClause = "FROM DemandeCreationCompte AS d ";
String whereClause = "WHERE d.email=:email";
int total = entityManager.createQuery(selectClause+fromClause+whereClause,Long.class).setParameter("email", email).getSingleResult().intValue();
log.debug("isEmailExist "+!(total==0)+" - total "+total);
return !(total == 0);
} |
J'ai bien l'information en base mais il me remonte a chaque fois false...
Voici ma classe de test :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| @Test
public void insert() {
DemandeCreationCompte demandeCreationCompte = new DemandeCreationCompte(
email1, pseudo1, "pass",
StaticMethodes.generateCode(StaticValues.CODE_LENGTH),
Calendar.getInstance());
DemandeCreationCompte ancienneDemandeCreationCompte = new DemandeCreationCompte(
email2, pseudo2, "pass",
StaticMethodes.generateCode(StaticValues.CODE_LENGTH),
StaticMethodes.removeDayToCalendar(Calendar.getInstance(), 3));
try {
daoDemandeCreationCompte.persist(demandeCreationCompte);
daoDemandeCreationCompte.persist(ancienneDemandeCreationCompte);
} catch (ExceptionDaoPersist e) {
e.printStackTrace();
}
Assert.assertEquals(2, daoDemandeCreationCompte.getAll().size());
}
@Test
public void isEmailExist(){
boolean exist = daoDemandeCreationCompte.isEmailExist(email1);
System.out.println(exist);
Assert.assertTrue(exist);
} |
Merci a ceux qui prendraient le temps de me répondre.