ejb@glassfish.java.net

Re: problems with ejb

From: Daniel Benítez <danibenitez_at_hotmail.com>
Date: Mon, 29 Sep 2008 13:22:14 +0200

Hi Kenneth,

Thanks, it is a good solution!

Daniel Benítez.

--------------------------------------------------
From: "Kenneth Saks" <Kenneth.Saks_at_Sun.COM>
Sent: Friday, September 26, 2008 7:14 PM
To: <ejb_at_glassfish.dev.java.net>
Subject: Re: problems with ejb

> Hi Daniel,
>
> Java EE environment annotations are only processed on the Application
> Client main class itself. You do have the option of looking up the same
> dependency declared by @EJB in the main class from your supporting
> classes, though. Here's an example :
>
>
> public class Main {
>
> @EJB(name="mySlessRef")
> private static StatelessSession sless;
>
> ...
> }
>
>
> public class StatelessSessionClase {
>
> public void getMemoriaServer(String Mensaje) {
> StatelessSession sless = (StatelessSession) new
> InitialContext().lookup("java:comp/env/mySlessRef");
> String Memoria = sless.getMemoriaServer();
> ...
> }
> }
>
> Note how the name() attribute value of @EJB matches the portion after
> "java:comp/env/" in the lookup.
>
> --ken
>
> On Sep 26, 2008, at 10:40 AM, Daniel Benítez wrote:
>
>> Hi people,
>>
>> I'm trying to create a EJB with Netbeans Enterprise Aplication but I
>> can't run it. I have a client and ejb modules, without web application
>> module. In my ejb project I have created an interface with @remote tag,
>> and other class with @stateless tag which implements the interface.
>>
>> Then, I create a class in a client module and I defined a static
>> variable of the interface type. In this class I try to call the remote
>> method. Finally I create a main class which calls the client class, but
>> the static EJB variable is null in all cases.
>>
>> What is my problem? I post too the client classes.
>>
>>
>> /// MAIN CLASS
>> public class Main {
>>
>>
>> public static void main(String args[]) {
>> StatelessSessionClase mSta = new StatelessSessionClase();
>> mSta.getMemoriaServer("Peticion de memoria");
>>
>> }
>> }
>>
>> /// CLASS WITH STATIC EJB VARIABLE
>> public class StatelessSessionClase {
>>
>> @EJB
>> private static StatelessSession sless;
>>
>> public void getMemoriaServer(String Mensaje) {
>>
>> String Memoria = sless.getMemoriaServer();
>> System.out.println(Mensaje + " " + Memoria);
>>
>> }
>>
>> }
>>
>> thank you!
>>
>> Daniel Benítez.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ejb-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: ejb-help_at_glassfish.dev.java.net
>
>