[jboss-user] [EJB 3.0] - Re: Can't inject PersistenceContext, NullPointerException wh

2009-01-03 Thread TristanS
Oddly, I got it working by luck and I'm still tracking down what I did. I tried 
your suggestion (unitName="...") and that didn't work. But I did get it working 
using a JNDI lookup rather than injection (see 
http://forum.hibernate.org/viewtopic.php?p=2402399#2402399 for more details).

As and when I find out what I did, I'll post back in case someone else sees 
this in the future

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4199314#4199314

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4199314
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Can't inject PersistenceContext, NullPointerException when u

2008-12-31 Thread TristanS
I have been working through a JBoss (5.0.0.CR2) example using the tutorial at 
http://www.netbeans.org/kb/55/ejb30-jboss.html#Exercise_5 (however using 
Netbeans 6.5).

I have an entity set up and upon deployment it is creating the table on the 
database. My problem is when I try to use a SLSB as a facade to retrieve 
entities back from the database. The generated code is as follows:



  | @Stateless
  | public class CustomerFacade implements CustomerFacadeLocal {
  | @PersistenceContext
  | private EntityManager em;
  | 
  | public void create(Customer customer) {
  | em.persist(customer);
  | }
  | 
  | public void edit(Customer customer) {
  | em.merge(customer);
  | }
  | 
  | public void remove(Customer customer) {
  | em.remove(em.merge(customer));
  | }
  | 
  | public Customer find(Object id) {
  | return em.find(Customer.class, id);
  | }
  | 
  | public List findAll() {
  | return em.createQuery("select object(o) from Customer as 
o").getResultList();
  | }
  | 
  | }

Unfortunately when I run this code, I get a NullPointerException upon usage of 
em because the PersistenceContext isn't being injected (I presume). This I'm 
sure is a config error, however I have also tried @PersistenceUnit(unitName 
= "PrototypeCRMSystem-ejbPU")
  | private EntityManagerFactory emf;
  | 
  | private EntityManager em = emf.createEntityManager(); which gives the 
same problem when accessing emf.

My persitence.xml is as follows:


  | http://java.sun.com/xml/ns/persistence"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd";>
  |   
  | org.hibernate.ejb.HibernatePersistence
  | java:/OracleDS
  | 
  |   
  |   
  |   
  | 
  |   
  | 
  | 

Am I missing something configuration-wise or is there a problem?

Thanks

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4199064#4199064

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4199064
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user