Bonjour a tous;
j'ai un problème de Cast: le problème est aussi simple mais Java me lance une exception un peu bizarre:
voila l'implémentation de l'interface:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 java.lang.ClassCastException: org.hibernate.impl.QueryImpl cannot be cast to com.fst.projet.model.Abonnement at com.fst.projet.service.AbonnementServiceImp.findByAbonne(AbonnementServiceImp.java:33)
l'implémentation du test:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 @Service(value="abonService") @Transactional public class AbonnementServiceImp implements AbonnementService { @Autowired private SessionFactory sessionFactory; @SuppressWarnings("unchecked") @Override public List<Abonnement> consltAbonnement() { return sessionFactory.getCurrentSession().createQuery("from Abonnement").list(); } public void enregistrer (Abonnement a) { sessionFactory.getCurrentSession().saveOrUpdate(a); } public Abonnement findByAbonne(int id){ Abonnement A; return A = (Abonnement) sessionFactory.getCurrentSession().createQuery("select x from Abonnement x where x.idAbonne='" + id + "'"); } }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 @Test public void testFindByAbonne() { int id=1; Abonnement ab=abonService.findByAbonne(id); assertNotNull(ab); assertEquals(1,ab.getIdAbonnement()); System.out.print(ab.getIdAbonnement()); }
merci a tous![]()
Partager