0 Replies Latest reply on Apr 12, 2007 10:11 AM by Guillaume Basilico

    EntityManagerFactory null ?

    Guillaume Basilico Newbie

      I want to access an entity from the client side, without using a session bean (If i use a session bean it works fine). I made a simple entity class :

      public class Produit implements Serializable {
       private String id;
       private String libelle;
       private int quantiteEnStock;
       public Produit() {
       public Produit(String id) {
       this.id = id;
       public Produit(String id, String libelle, int quantiteEnStock) {
       this.id = id;
       this.libelle = libelle;
       this.quantiteEnStock = quantiteEnStock;
       public String getLibelle() {
       return libelle;

      I have also made a persistence.xml, which i put in the META-INF directory :
       <persistence-unit name="Produit">
       <property name="hibernate.hbm2ddl.auto" value="update"/>
       <property name="jboss.entity.manager.factory.jndi.name" value="Produit"/>

      On the client side, i have the following code :

      Hashtable env = new Hashtable();
      Context ctx = new InitialContext(env);
      NamingEnumeration ne = ctx.list("");
       NameClassPair nc = (NameClassPair)ne.next();
       System.out.println("Entry is ... "+nc.getName()+" -- "+nc.getClassName());
      Object obj = ctx.lookup("Produit");

      I can see the "Produit" in the list (it's type is org.jboss.ejb3.entity.InjectedEntityManagerFactory) but the lookup returns null. I also tried with
      EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("Produit");
      but it doesn't work either.
      Do you have any clue of what i am doing wrong ? Is it at least possible ?
      I'm using JBoss 4.0.5 and Eclipse 3.2.
      Thanks in advance for your help.

      Guillaume Basilico