Why entitymanager is null???
kdcosta.mail.dcosta.gmail.com May 13, 2008 7:28 AMhi
I am entirely new to seam framework.
I have imported a seam project into my workspace created in another machine.and also the database is in that system only.so the connection string ,system name is given rather than localhost.
when in my class in used @PresistanceContext to get the entity manager.
But what ever the query be i am getting a null pointer exception.
So i tried to print what the entitiy manager is.So its getting printed as null.
Why is it so???
Below are the code
@Scope(ScopeType.SESSION) @Stateless public class CompanyManager implements IFCompanyManager { public Company m_Company; public UserManager m_UserManager; @PersistenceContext EntityManager em; public CompanyManager(){ } @In Company company; /** * * @param CompanyDetails * @param SuperUserName * @param SuperUserEmail * @param Login */ public Status RegisterCompany(IFCompany CompanyDetails, String SuperUserName, String SuperUserEmail, String Login){ try { System.out.println("inside reg button in manager"); List existing = em.createQuery("select u.companyId from Company u").getResultList(); } catch (Exception e) { System.out.println("inside catch"); e.printStackTrace(); } return Status.SUCCESS; }
Components.xml
<?xml version="1.0" encoding="UTF-8"?> <components xmlns="http://jboss.com/products/seam/components" xmlns:core="http://jboss.com/products/seam/core" xmlns:drools="http://jboss.com/products/seam/drools" xmlns:security="http://jboss.com/products/seam/security" xmlns:mail="http://jboss.com/products/seam/mail" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.2.xsd http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-1.2.xsd http://jboss.com/products/seam/security http://jboss.com/products/seam/security-1.2.xsd http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-1.2.xsd http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.2.xsd"> <core:init debug="true" jndi-pattern="@jndiPattern@"/> <core:manager concurrent-request-timeout="500" conversation-timeout="120000" conversation-id-parameter="cid" conversation-is-long-running-parameter="clr"/> <core:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/AWBEntityManagerFactory"/> <core:ejb installed="@embeddedEjb@"/> <drools:rule-base name="securityRules"> <drools:rule-files> <value>/security.drl</value> </drools:rule-files> </drools:rule-base> <security:identity authenticate-method="#{authenticator.authenticate}" security-rules="#{securityRules}"/> <event type="org.jboss.seam.notLoggedIn"> <action expression="#{redirect.captureCurrentView}"/> </event> <event type="org.jboss.seam.postAuthenticate"> <action expression="#{redirect.returnToCapturedView}"/> </event> <mail:mail-session host="localhost" port="2525" username="test" password="test" /> <!-- For use with jBPM pageflow or process management --> <!-- <core:jbpm> <core:process-definitions></core:process-definitions> <core:pageflow-definitions></core:pageflow-definitions> </core:jbpm> --> </components>
peristance.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- Persistence deployment descriptor for tests --> <persistence 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" version="1.0"> <persistence-unit name="AWB"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/AWBTestDatasource</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> <property name="hibernate.show_sql" value="true"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/AWBEntityManagerFactory"/> </properties> </persistence-unit> </persistence>
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?> <ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" version="3.0"> <interceptors> <interceptor> <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class> </interceptor> </interceptors> <assembly-descriptor> <interceptor-binding> <ejb-name>*</ejb-name> <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class> </interceptor-binding> </assembly-descriptor> </ejb-jar>
And the ds.xml file is in the server deploy folder also.
Plz help me
it would be a great help.