6 Replies Latest reply: Apr 9, 2010 9:51 PM by Chun Shin RSS

EJB and Injection

Robert Diaz Newbie

Hi guys,
I have a few questions about injection. First off, yes, I know there is a section on this in the Seam reference PDF, and I did read it thoroughly. Second, I can get it to work, just not the way I want it to.


Ok so here's the problem: I have a JSF page that registers a user that is backed by a stateful backing bean. To keep with the methodology of tiered design, I did not place any logic or database access in that backing bean. There is a logic class that is associated with that bean and also a database class that goes with the logic class. Whenever I try and inject my EntityManager into the database class, it tells me that it is null, yet if I inject it into the backing bean and, through some icky looking code, pass the EntityManager back through the classes to the database class in order to use it, everything works just fine.


I have looked through the reference PDF and the seam examples thoroughly and I have everything set up the same way you guys do, except that all of your logic, database access, and getters and setters for the page are in the same class.


Is this just poor design on my part and I shouldn't be doing things like this or am I correct and something is just not working the way it should be?


Thanks a lot for any help,
Robert


Below are the classes I spoke of before:


RegisterBean:


@Stateful
@Scope(SESSION)
@Name("registrationBean")
public class RegisterBean implements Register, Serializable{

    private FacesMessages facesMessages;
    
    private String username;
    private String password;
    private String firstName, middleName, lastName;
    private String address, city, state;
    private int zip;
    private String phone;
    private String organizationName;
    private String email;
    
    private RegistrationLogic regLogic;
    
    public RegisterBean() {
        username = "";
        password = "";
        firstName = "";
        middleName = "";
        lastName = "";
        address = "";
        city = "";
        state = "";
        zip = 0;
        phone = "";
        organizationName = "";
        email = "";
        regLogic = new RegistrationLogic();
        facesMessages = FacesMessages.instance();
    }
    
    public String submit()
    {
        regLogic.fill(username, password, firstName, middleName, lastName, address, city, state, zip, phone, organizationName, email);
        
        if(regLogic.fillEntities()){
            facesMessages.add("Registration Successful","");
            return "submitted";
        }
        else{
            facesMessages.add("Error Submitting Information","");
            return "notSubmitted";
        }
    }
    
    public String back()
    {
        return "back";
    }
    
    public String restart()
    {
        return null;
    }
    
    @Destroy @Remove                                                                      
    public void destroy() {}

(getters and setters for the page members)



RegistrationLogic:
(RegistrationDataModel is just a holder for all of the information)


@Stateful
@Scope(SESSION)
@Name("registrationLogic")
public class RegistrationLogic implements RegistrationLogicInterface, Serializable{

    private FacesMessages facesMessages;
    
    private RegistrationDatabaseManager dbManager;
    
    private RegistrationDataModel regDataModel;
    
    private PersonT p;
    private AddressT a;
    private ElectronicAddressT phoneEA;
    private ElectronicAddressT emailEA;
    private UserT user;
    private PersonAddress pAddress;
    private PersonElectronicAddress pPhoneEA;
    private PersonElectronicAddress pEmailEA;
    private PersonOrganization pOrg;
    private PersonUser pUser;

    public RegistrationLogic() {
        dbManager = new RegistrationDatabaseManager();
        p = new PersonT();
        a = new AddressT();
        phoneEA = new ElectronicAddressT();
        emailEA = new ElectronicAddressT();
        user = new UserT();

        pAddress = new PersonAddress();
        pPhoneEA = new PersonElectronicAddress();
        pEmailEA = new PersonElectronicAddress();
        pOrg = new PersonOrganization();
        pUser = new PersonUser();

        facesMessages = FacesMessages.instance();

        regDataModel = new RegistrationDataModel();
    }

    public void fill(String username, String password, String firstName,
            String middleName, String lastName, String address, String city,
            String state, int zip, String phone, String organizationName,
            String email) {

        regDataModel.fillFields(username, password, firstName, middleName, lastName, address, city, state, zip, phone, organizationName, email);
    }

    public boolean fillEntities() {

        // error checking for all of the values

        if (regDataModel.getUsername().equals("")) {
            facesMessages.add("Please enter a username", "");
            return false;
        }

        if (regDataModel.getPassword().equals("")) {
            facesMessages.add("Please enter a password", "");
            return false;
        }

        if (regDataModel.getFirstName().equals("")) {
            facesMessages.add("Please enter a first name", "");
            return false;
        }

        if (regDataModel.getLastName().equals("")) {
            facesMessages.add("Please enter a last name", "");
            return false;
        }

        if (regDataModel.getAddress().equals("")) {
            facesMessages.add("Please enter a street address", "");
            return false;
        }

        if (regDataModel.getCity().equals("")) {
            facesMessages.add("Please enter a city", "");
            return false;
        }

        if (regDataModel.getState().equals("")) {
            facesMessages.add("Please enter a state", "");
            return false;
        }

        if (regDataModel.getZip() == 0) {
            facesMessages.add("Please enter a zip code", "");
            return false;
        }

        if (!regDataModel.getPhone().equals("")) {
            String regex = "(\\d-)?(\\d{3}-)?\\d{3}-\\d{4}";
            Pattern pattern = Pattern.compile(regex);
            Matcher m = pattern.matcher(regDataModel.getPhone());
            if (!m.matches()) {
                facesMessages.add("Phone number is in the wrong format. The correct format is 555-555-5555", "");
                return false;
            }
        } else {
            facesMessages.add("Please enter a phone number", "");
            return false;
        }

        if (!regDataModel.getEmail().equals("")) {
            String regex = ".+@.+\\..+";
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(regDataModel.getEmail());
            if (!matcher.matches()) {
                facesMessages.add("Email address is in the wrong format", "");
                return false;
            }
        } else {
            facesMessages.add("Please enter an email address", "");
            return false;
        }

        try {
            // fill in the person object
            p.setId(UUID.randomUUID().toString());
            p.setFname(regDataModel.getFirstName());
            p.setMname(regDataModel.getMiddleName());
            p.setLname(regDataModel.getLastName());

            // fill in the address object
            a.setId(UUID.randomUUID().toString());
            a.setAddress(regDataModel.getAddress());
            a.setCity(regDataModel.getCity());
            a.setState(regDataModel.getState());
            a.setZip(regDataModel.getZip());

            // fill in the user object
            user.setId(UUID.randomUUID().toString());
            user.setUsername(regDataModel.getUsername());
            user.setPassword(regDataModel.getPassword());

            // fill in the phone electronic address object
            phoneEA.setId(UUID.randomUUID().toString());
            phoneEA.setPhone(regDataModel.getPhone());

            // fill in the email electronic address object
            emailEA.setId(UUID.randomUUID().toString());
            emailEA.setEmail(regDataModel.getEmail());

            // get the id of the organization from the name
            HashMap peopleOrganizationUUID = dbManager.getPersonOrganizationUUID(regDataModel.getOrganizationName());

            //////////////////////////////////////////
            // fill out the association entities
            //////////////////////////////////////////

            // fill in the person address object
            pAddress.setId(new PersonAddressId(p.getId(), a.getId()));
            pAddress.setPersonT(p);
            pAddress.setAddressT(a);

            // fill in the person phone electronic address object
            pPhoneEA.setId(new PersonElectronicAddressId(p.getId(), phoneEA.getId(), 1));
            pPhoneEA.setPersonT(p);
            pPhoneEA.setElectronicAddressT(phoneEA);

            // fill in the person email electronic address object
            pEmailEA.setId(new PersonElectronicAddressId(p.getId(), emailEA.getId(), 2));
            pEmailEA.setPersonT(p);
            pEmailEA.setElectronicAddressT(emailEA);

            // get the organization's id from the map
            String id = (String) peopleOrganizationUUID.get("orgID");

            // fill in the person organization object
            pOrg.setId(new PersonOrganizationId(p.getId(), id));
            pOrg.setOrganizationT(dbManager.getOrganizationById(id));

            // fill in the person user object
            pUser.setId(new PersonUserId(p.getId(), user.getId()));
            pUser.setPersonT(p);
            pUser.setUserT(user);

            // take all of the objects and condense them into a map so they can be easily passed to the database manager
            HashMap map = regDataModel.condenseEntities(p, a, phoneEA, emailEA, user, pAddress, pPhoneEA, pEmailEA, pOrg, pUser);

            dbManager.persist(map);

            return true;
        } catch (Exception exception) {
            facesMessages.add("An error has occured while inserting the information into our system. Please check your information for accuracy and try again.", "");
            exception.printStackTrace();
        }
        return false;
    }

    @Destroy @Remove                                                                      
    public void destroy() {}
    
}




RegistrationDatabaseManager:


@Stateful
@Scope(SESSION)
@Name("registrationDatabaseManager")
public class RegistrationDatabaseManager implements Serializable, RegistrationDatabaseManagerInterface {

    @In
    EntityManager entityManager;

    /**
     * Queries the database for an OrganizationT object by it's UUID.
     * 
     * @param id
     * @return An organization object from the database
     * @see OrganizationT
     */
    public OrganizationT getOrganizationById(String id) {
        OrganizationT o = new OrganizationT();

        //o = entityManager.find(OrganizationT.class, id);

        return o;
    }

    /**
     * Queries the database for an OrganizationT object by it's name.
     * 
     * @param organizationName
     * @return
     * 
     * @see OrganizationT
     */
    public HashMap getPersonOrganizationUUID(String organizationName) {
        String id = "";
        HashMap map = new HashMap();

        id = (String) entityManager.createQuery("select id from OrganizationT o where o.name = :name").setParameter("name", organizationName).getSingleResult();

        map.put("orgName", organizationName);
        map.put("orgID", id);

        return map;
    }

    /**
     * This takes the map of entities and persists them into the database.
     * @param map
     */
    public void persist(HashMap map) {
        System.out.println("About to persist to the database");

        entityManager.persist(map.get("PersonT"));
        entityManager.persist(map.get("AddressT"));
        entityManager.persist(map.get("PhoneElectronicAddress"));
        entityManager.persist(map.get("EmailElectronicAddress"));
        entityManager.persist(map.get("User"));
        entityManager.persist(map.get("PersonAddress"));
        entityManager.persist(map.get("PersonPhoneElectronicAddress"));
        entityManager.persist(map.get("PersonPhoneElectronicAddress"));
        entityManager.persist(map.get("PersonOrganization"));
        entityManager.persist(map.get("PersonUser"));

        System.out.println("All done!!");
    }

    @Destroy @Remove                                                                      
    public void destroy() {}
    

  • 1. Re: EJB and Injection
    Tom Goring Apprentice

    Your problem is here I think:



     public RegistrationLogic() {
            dbManager = new RegistrationDatabaseManager();
           




    You MUST not use new to create Seam based objects (injection will not occur).



    You should do something like:



    @In(value="registrationDatabaseManager", create=true)
    RegistrationDatabaseManager dbManager
    



  • 2. Re: EJB and Injection
    Robert Diaz Newbie

    Thanks for the reply. I tried that and it gave me this error;


    javax.faces.FacesException: javax.el.ELException: /Register.xhtml @32,84 value="#{registrationBean.username}": Error reading 'username' on type org.javassist.tmp.java.lang.Object_$$_javassist_1
         at javax.faces.component.UIOutput.getValue(UIOutput.java:176)
         at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:189)
         at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:320)
         at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:200)
         at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
         at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
         at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
         at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
         at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
         at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
         at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:199)
         at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:194)
         at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
         at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
         at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
         at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
         at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
         at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
         at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
         at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
         at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
         at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
         at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
         at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
         at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
         at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
         at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
         at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
         at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
         at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
         at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
         at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
         at java.lang.Thread.run(Thread.java:619)
    Caused by: javax.el.ELException: /Register.xhtml @32,84 value="#{registrationBean.username}": Error reading 'username' on type org.javassist.tmp.java.lang.Object_$$_javassist_1
         at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
         at javax.faces.component.UIOutput.getValue(UIOutput.java:173)
         ... 59 more
    Caused by: javax.ejb.EJBTransactionRolledbackException: could not set field value: registrationBean.registrationLogic
         at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
         at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
         at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
         at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:204)
         at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:100)
         at $Proxy211.getUsername(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
         at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
         at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
         at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:41)
         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
         at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
         at org.javassist.tmp.java.lang.Object_$$_javassist_1.getUsername(Object_$$_javassist_1.java)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
         at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
         at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
         at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
         at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
         at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
         at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
         ... 60 more
    Caused by: java.lang.IllegalArgumentException: could not set field value: registrationBean.registrationLogic
         at org.jboss.seam.Component.setFieldValue(Component.java:1789)
         at org.jboss.seam.Component.access$600(Component.java:139)
         at org.jboss.seam.Component$BijectedField.set(Component.java:2622)
         at org.jboss.seam.Component.injectAttributes(Component.java:1598)
         at org.jboss.seam.Component.inject(Component.java:1416)
         at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:45)
         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:26)
         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:27)
         at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
         at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
         at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
         at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
         at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
         at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
         ... 102 more
    Caused by: java.lang.IllegalArgumentException: Could not set field value by reflection: RegisterBean.regLogic on: us.gaaoc.ejb.RegisterBean with value: class org.javassist.tmp.java.lang.Object_$$_javassist_2
         at org.jboss.seam.util.Reflections.set(Reflections.java:79)
         at org.jboss.seam.Component.setFieldValue(Component.java:1785)
         ... 130 more
    Caused by: java.lang.IllegalArgumentException: Can not set us.gaaoc.ejb.logic.RegistrationLogic field us.gaaoc.ejb.RegisterBean.regLogic to org.javassist.tmp.java.lang.Object_$$_javassist_2
         at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
         at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
         at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
         at java.lang.reflect.Field.set(Field.java:657)
         at org.jboss.seam.util.Reflections.set(Reflections.java:64)
         ... 131 more
    
    



    I changed it from where I created a new object to where I injected the object like so:


    @In(value="registrationLogic")
    private RegistrationLogic regLogic;
    
    @In(value="registrationDatabaseManager")
    private RegistrationDatabaseManager dbManager;
    



    I also tried to make the fields not private, thinking it may change something since yours were not private, but it didn't change anything.


    There has to be something small that I'm missing that is causing this error to occur.

  • 3. Re: EJB and Injection
    Ashvini Tharval Newbie

    have u defined the getter setter for userBean in the local interface.
    I was getting this error when i did not define these methods in the interface of stateless session bean which acted as backing bean.

  • 4. Re: EJB and Injection
    Robert Diaz Newbie

    One more thing I forgot to mention... I added @AutoCreate to the classes so I didn't have to put


    @In(create=true)
    



    userBean? I think you meant username. Username has get and set methods. The only reason that error was called was because the object was not properly injected into the page. When that happens, other parts of the page will mess up, causing weird errors to occur like the one above.


    If you look at the bottom of the stack trace, it shows that an IllegalArgumentException caused the entire thing.

  • 5. Re: EJB and Injection
    Ray Di Ciaccio Newbie

    I ran into a similar problem and was eventually able to work through it...
    Once I changed the type of the injected component to the interface (as opposed to the implemented type), it all worked.


    e.g. I had something like


    @In(value="incidentManager") IncidentManager im;
    



    And changed it to


    @In(value="incidentManager") IncidentManagerInt im;
    



    where IncidentManagerInt is the interface implemented by IncidentManager


    hope this helps someone

  • 6. Re: EJB and Injection
    Chun Shin Newbie

    what a coincidence...I just ran into the same problem and like Ray said you need to use an interface instead of a concrete class. It took me almost an hour to figure that out.