[jboss-user] [EJB 3.0] - EntityManagerFactory null ?
gbasilico
do-not-reply at jboss.com
Thu Apr 12 10:11:58 EDT 2007
Hello,
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 :
| @Entity
| public class Produit implements Serializable {
|
| @Id
| private String id;
| private String libelle;
| private int quantiteEnStock;
|
| public Produit() {
| super();
| }
|
| 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>
| <persistence-unit name="Produit">
| <provider>org.hibernate.ejb.HibernatePersistence</provider>
| <jta-data-source>java:/DefaultDS</jta-data-source>
| <properties>
| <property name="hibernate.hbm2ddl.auto" value="update"/>
| <property name="jboss.entity.manager.factory.jndi.name" value="Produit"/>
| </properties>
| </persistence-unit>
| </persistence>
|
On the client side, i have the following code :
| Hashtable env = new Hashtable();
| env.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
| env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
| env.put("java.naming.provider.url","localhost:1099");
|
| Context ctx = new InitialContext(env);
|
| NamingEnumeration ne = ctx.list("");
| while(ne.hasMore())
| {
| NameClassPair nc = (NameClassPair)ne.next();
| System.out.println("Entry is ... "+nc.getName()+" -- "+nc.getClassName());
| }
| Object obj = ctx.lookup("Produit");
| System.out.println(obj.toString());
|
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.
Regards,
Guillaume Basilico
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4036732#4036732
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4036732
More information about the jboss-user
mailing list