2017-01-04 6 views
0

私は、新しいejbClass(params)を呼び出すためのインターフェイスと新しいクラスを持つクラスを持っています。これにはejb呼び出し(以下のコード)が含まれています。そのクラスからejbを呼び出すと、nullポイント例外が発生します。EJBヌルポイント例外

public class ProfileDTO { 

    private Profile profileEntity; 

    @EJB 
    private ProfileRemoteBean profileBean; //remote bean is interface name 

    public ProfileDTO(String firstName, String lastName, Date birthDate, String gender, String country, String district, String city, String identificationNo, String idCardNo, String phone) { 

     createProfile(); 

    } 

    public void createProfileEntity() { 

     Profile profileEntity = new Profile(); 

     //deleted code for stackoverflow 
     //................................... 
     this.profileEntity = profileEntity; 
    } 

    public Profile getProfileEntity(){ 
     return this.profileEntity; 
    } 

    private void createProfile() { 
     createProfileEntity(); 
     profileBean.addProfile(getProfileEntity()); // profile bean null point here 
    } 

} 

EJBインタフェース

@Remote 
public interface ProfileRemoteBean { 
    public List<Profile> getProfile(); 
} 

EJBクラス

@Stateless 
public class ProfileBean implements ProfileRemoteBean,Serializable{ 

    @PersistenceContext(unitName = "com.ulbs.admission.core_AdmissionCoreDBEJB_ejb_1.0-SNAPSHOTPU", type = PersistenceContextType.TRANSACTION) 
    private EntityManager entityManager; 



    @Override 
    public List<Profile> getProfile() { 
    TypedQuery<Profile> query = entityManager.createNamedQuery("Profile.findAll", Profile.class); 
    return query.getResultList(); 
    } 
} 

内のEJBメソッドを呼び出す

クラスは、あなたは私にいくつかのヒントや解決策をお願いできますか?

ありがとうございます!

答えて

1

しようとしているものは動作していません。EJBは管理対象クラスではないため、DTOに挿入することはできません。

あなたの依存性注入をリファクタリングするか、ProfileRemoteBeanをコンストラクタ経由でProfileDTOに渡します。

0

あなたのコードはOKのようですが、代わりにNPEがあなたのメソッドProfileRemoteBean.addProfile(Profile profile)から来ていませんか?

貼り付けることは可能でしょうか?

+0

はその行に由来しますが、profileBeanはデバッガ上ではnullであるため –

関連する問題