users@glassfish.java.net

Re: Retrieving an EntityManagerFactory

From: <glassfish_at_javadesktop.org>
Date: Tue, 11 Dec 2007 08:14:07 PST

Hi,
I'm new to JPA and i'm using it in my current project

my persistence.xml looks like this

<persistence-unit name="ShoppingCartEStore">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <jta-data-source>
                        java:/ShoppingCartEStoreDatasource
                </jta-data-source>
                <properties>
                        <property name="hibernate.connection.url"
                                value="jdbc:mysql://localhost:3306/shopping_cart" />
                        <property name="hibernate.connection.driver_class"
                                value="com.mysql.jdbc.Driver" />
                        <property name="hibernate.connection.password" value="123456" />
                        <property name="hibernate.connection.username" value="root" />
                        <!-- <property name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
                        <property name="hibernate.hbm2ddl.auto" value="update" />
                        <property name="hibernate.cache.use_query_cache"
                                value="true" />
                        <property name="hibernate.show_sql" value="true" />
                        <property name="hibernate.dialect"
                                value="org.hibernate.dialect.MySQLDialect" />
                                         <property name="jboss.entity.manager.jndi.name" value="java:/ShoppingCartEStoreEntityManager"/>
                        <property name="jboss.entity.manager.factory.jndi.name"
                                value="java:/ShoppingCartEStoreEntityManagerFactory" />
                </properties>

I had also included

<component name="userDatabase"
    class="org.jboss.seam.core.ManagedPersistenceContext">
    <property name="persistenceUnitJndiName">
    java:/ShoppingCartEStoreEntityManagerFactory
    </property>
    </component>

in my components.xml file


and my persistence class looks like

@PersistenceContext(name = "userDatabase", unitName="ShoppingCartEStore")
@Stateful
@Name("MySqlPersistence")
public class PersistMySqlController implements PersistMysql, Serializable
{private EntityManager em;
public void persistOrder(Order order)
        {
                // TODO Auto-generated method stub
                
                
                try
                {
                InitialContext ic = new InitialContext();
                em = (EntityManager) ic.lookup("java:/userDatabase");
                em.persist(order);
                }
                catch(Exception e)
                {
                        
                        
                }
public void destroy()
        {
                // TODO Auto-generated method stub
                em.close();

        }

        
}


I deploy the application on jboss and i get the

--- MBeans waiting for other MBeans ---
ObjectName: persistence.units:ear=ShoppingCartBase.ear,jar=ShoppingCartBase.jar,unitName=ShoppingCartEStore
  State: FAILED
  Reason: java.lang.NullPointerException
  I Depend On:
    jboss.jca:service=DataSourceBinding,name=ShoppingCartEStoreDatasource
  Depends On Me:
    jboss.j2ee:ear=ShoppingCartBase.ear,jar=ShoppingCartBase.jar,name=PersistMySqlController,service=EJB3

ObjectName: jboss.j2ee:ear=ShoppingCartBase.ear,jar=ShoppingCartBase.jar,name=PersistMySqlController,service=EJB3
  State: NOTYETINSTALLED
  I Depend On:
    persistence.units:ear=ShoppingCartBase.ear,jar=ShoppingCartBase.jar,unitName=ShoppingCartEStore

--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: persistence.units:ear=ShoppingCartBase.ear,jar=ShoppingCartBase.jar,unitName=ShoppingCartEStore
  State: FAILED
  Reason: java.lang.NullPointerException
  I Depend On:
    jboss.jca:service=DataSourceBinding,name=ShoppingCartEStoreDatasource
  Depends On Me:
    jboss.j2ee:ear=ShoppingCartBase.ear,jar=ShoppingCartBase.jar,name=PersistMySqlController,service=EJB3


I'm tryingto solve this for the last four days and i still get the same error. what could be the problem and how could i solve that. Please help me, thanks in advance
[Message sent by forum member 'dev_ejb' (dev_ejb)]

http://forums.java.net/jive/thread.jspa?messageID=249527