Which web framework are you using? If it's Struts 2, the manager is injected via the setXXXManager method in your action. However, it's only injected when running in the server since the Spring Plugin facilitates this. For your tests, you should manually call setXXXManager. The tests generated by AMP should do this for you. If they don't, it may be a bug.

Matt

On Dec 16, 2007, at 8:22 AM, Vachel Chan wrote:


hi all:

    The following code is my model class. Specially, the key property
"regionId" is a String, not a Long type.

When I use "mvn appfuse:gen -Dentity=DRegion " to generate all the code and
run "mvn integration-test",
there is an Excepion :

  java.lang.NullPointerException
        at com.huaat.webapp.action.DRegionAction.list(DRegionAction.java:38)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39)
        ................
             ..........

  Then  I check the code  DRegionAction.java in line 38:  dRegions =
dRegionManager.getAll();
Obviously , the dRegionManager is NULL ! I check every config files ,
the dRegionManager bean
was added correctly, including in applicationcontext.xml. like this:

     <!--DRegionManager-START-->
    <bean id="dRegionManager"
class="org.appfuse.service.impl.GenericManagerImpl" autowire="byName">
        <constructor-arg>
<bean class="org.appfuse.dao.hibernate.GenericDaoHibernate">
                <constructor-arg value="com.myproject.model.DRegion"/>
                <property name="sessionFactory" ref="sessionFactory"/>
            </bean>
        </constructor-arg>
    </bean>
    <!--DRegionManager-END-->

 now the question is, why the dRegionManager is not injected in my
DRegionAction ?

 and why every thing is ok when the model key property chang to Long,
instead of a String ?

 thanks advanced!

--------------------------- DRegion.java
-------------------------------------

package com.myproject.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.appfuse.model.BaseObject;

@Embeddable
@Entity
@Table(name="d_region")
public class DRegion extends BaseObject implements Serializable {
        
    private static final long serialVersionUID = 8317259246781769186L;
    private String regionId;
    private String regionName;

    @Id
    @Column(name="region_id", nullable=false, length=3)
    public String getRegionId() {
        return this.regionId;
    }

    public void setRegionId(String regionId) {
        this.regionId = regionId;
    }

    @Column(name="region_name", nullable=false, length=32)
    public String getRegionName() {
        return this.regionName;
    }

    public void setRegionName(String regionName) {
        this.regionName = regionName;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        DRegion pojo = (DRegion) o;

        if (regionName != null ? !regionName.equals(pojo.regionName) :
pojo.regionName != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (regionName != null ? regionName.hashCode() : 0);

        return result;
    }

    public String toString() {
StringBuffer sb = new StringBuffer(getClass().getSimpleName ());

        sb.append(" [");
sb.append("regionId").append("='").append(getRegionId ()).append("',
");

sb.append("regionName").append("='").append(getRegionName()).append ("'");
        sb.append("]");

        return sb.toString();
    }

}




--
View this message in context: http://www.nabble.com/Why-the- GenericManager-can-not-be-injected-when-the-model-ID-is-a-String--- tp14362529s2369p14362529.html
Sent from the AppFuse - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to