users@glassfish.java.net

Re: Define two instances of same bean in ejb-jar and sun-ejb-jar

From: <glassfish_at_javadesktop.org>
Date: Tue, 16 Jun 2009 02:11:44 PDT

Hi,

I did as you suggested and removed the @MessageDriven annotation. This helped and deployment went fine.

But now I also saw behaviour which might be related to the bug you mentioned. Sometimes the injection of the env-entry into the String variable did not work and I saw "null" in the debug output. I simply output the following:
"instance = " + this.toString() + " - someEnv = " + someEnv + " - message = " + ((TextMessage) message).getText() )

Here is example output:

[#|2009-06-16T10:46:03.453+0200|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=20;_ThreadName=p: thread-pool-1; w: 10;|
instance = testing.ejbeans.testmultipleejbs.TestMDB_at_2e9157 - someEnv = aString|#]

[#|2009-06-16T10:46:03.454+0200|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=20;_ThreadName=p: thread-pool-1; w: 10;|
instance = testing.ejbeans.testmultipleejbs.TestMDB_at_2e9157 - someEnv = aString - message = this is a test|#]

[#|2009-06-16T10:46:03.591+0200|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=20;_ThreadName=p: thread-pool-1; w: 10;|
instance = testing.ejbeans.testmultipleejbs.TestMDB_at_115eab5 - someEnv = null|#]

[#|2009-06-16T10:46:03.592+0200|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=20;_ThreadName=p: thread-pool-1; w: 10;|
instance = testing.ejbeans.testmultipleejbs.TestMDB_at_115eab5 - someEnv = null - message = this is another test|#]

So I decided to look the env-entry up via InitialContext in the @PostConstruct method. This worked.
But then I observed strange behaviour after a Glassfish restart. The first time I started the test after the GF restart, there was only one bean created (I could tell from this.toString()). The bean then received both messages I sent in the UnitTest. However, after I re-deployed the bean and started the test again, two different instances are created. I could not reproduce this regularly, it only appeared twice.

After this I added the following to the deployment descriptor:
<injection-target>
<injection-target-class>testing.ejbeans.testmultipleejbs.TestMDB</injection-target-class>
<injection-target-name>someEnv</injection-target-name>
</injection-target>

Then the injection worked as expected. But shouldn't it work without that?

Attached is an updated MDB and test case.

Thanks,
Chris.
[Message sent by forum member 'chrjohn' (chrjohn)]

http://forums.java.net/jive/thread.jspa?messageID=351348