Hi all, Scenario/Problem: Client needs to get an Entitymanager / Entitymangerfactory via JNDI.
Studying docs/wikis/forum I came up with this: | try { | Context context = new InitialContext(); | EntityManagerFactory emf = (EntityManagerFactory) context.lookup("java:/EntityManagerFactory"); | logger.debug("emf "+emf); | //manager = emf.createEntityManager(); | persistence.xml: | <persistence-unit name="mos"> | <provider>org.hibernate.ejb.HibernatePersistence</provider> | <jta-data-source>java:/mystDS</jta-data-source> | <properties> | <!-- JNDI name for EntityManager+Factory (we need this for non container managed access to this PU --> | <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagerFactory"/> | <property name="jboss.entity.manager.jndi.name" value="java:/EntityManager"/> | <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/> | <property name="hibernate.hbm2ddl.auto" value="update"/> | </persistence-unit> | </persistence> | Problem: It always returns null :( I've also tried it that way: | EntityManagerFactory emf2 =Persistence.createEntityManagerFactory("mos"); | emf2.cerate | //manager = emf2.createEntityManager(); | (and putting persistence.xml to META-INF) but this gives this exception: | Exception in thread "main" javax.persistence.PersistenceException: java.lang.NullPointerException | at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:173) | at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:103) | at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37) | at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27) | at com.ttech.myst.client.test.Test2.main(Test2.java:68) | Caused by: java.lang.NullPointerException | at org.hibernate.ejb.packaging.PersistenceXmlLoader.deploy(PersistenceXmlLoader.java:68) | at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:139) | ... 4 more | For stateless/full beans getting the entitymanager via injection works wunderful, (via @PersistenceContext(unitName="...")) and I'm awre that calling beans in hte client rather than putting the bussinesslayer/EJB3 queries directly into the client is suboptimal, but I cant avoid it in my case :-((( (long story) Any help would be greatly appriciated :) thx in advance, nick View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3928731#3928731 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3928731 ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user