[prev in list] [next in list] [prev in thread] [next in thread]
List: jboss-user
Subject: [jboss-user] [EJB 3.0] - Can't inject PersistenceContext,
From: TristanS <do-not-reply () jboss ! com>
Date: 2008-12-31 14:57:14
Message-ID: 31256949.1230735434795.JavaMail.jboss () colo-br-02 ! atl ! jboss ! com
[Download RAW message or body]
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<Customer> 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:
<?xml version="1.0" encoding="UTF-8"?>
| <persistence version="1.0" xmlns="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"> | <persistence-unit \
name="PrototypeCRMSystem-ejbPU" transaction-type="JTA"> | \
<provider>org.hibernate.ejb.HibernatePersistence</provider> | \
<jta-data-source>java:/OracleDS</jta-data-source> | <properties>
| <property name="hibernate.dialect" \
value="org.hibernate.dialect.Oracle9iDialect"/> | <property \
name="hibernate.hbm2ddl.auto" value="update"/> | <property \
name="hibernate.show_sql" value="true" /> | </properties>
| </persistence-unit>
| </persistence>
|
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic