je vais epliquer mieux ma question
j'ai crée un projet dans le quel j'implémente hibernate
don ce projet contient :
fichier de configuration hibernate: hibernate.cfg.xml
fihier de mapping
classes javabean: contient getters/setters
classe : HibernateUtil
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
| ....................
private static final SessionFactory sessionFactory;
static {
try {
sessionFactory =new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException("Problème de configuration : "+ ex.getMessage(), ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession()throws HibernateException {
Session s = (Session) session.get();
// Ouvre une nouvelle Session, si ce Thread n'en a aucune
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession()throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
............ |
apres je crée un projet ejb (session) qui contient une interface Xx.java
et une classe XxBean.java, dans cette classe j'appelle la classe hibernateUtil
1 2 3 4 5 6 7 8 9 10 11 12 13
| .........
public void ajouter(String rue, String ville) throws HibernateException {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
Adresse adresse = new Adresse();
adresse.setRue(rue);
adresse.setVille(ville);
session.save(adresse);
tx.commit();
HibernateUtil.closeSession();
........ |
je deploi l'ejb dans le serveur Jboss
apres je crée un projet java qui contient une classe de test
1 2 3 4 5 6 7 8 9 10 11 12 13
| public class Test {
public static void main(String[] args) throws HibernateException {
try {
Context context = new InitialContext();
Xx adr = (Xx)context.lookup("XxBean/remote");
adr.ajouter("rue","ville");
}catch (NamingException e) {
e.printStackTrace();
}
}
} |
quand j'execute je recoi l'erreur suivante
Exception in thread "main" javax.ejb.EJBException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: com/cdvm/dao/HibernateUtil
il ne reconnait pas la classe Hibernate , pourtant j'ai ajouté le projet dans le build path, j'ai fait les import
c pour cela que je demande comment on configure hibernate dans Jboss pour qu'il soit accecible aux ejb session qui implementent le metier
Partager