users@glassfish.java.net

Re: howto: How can the same bean multiple times configured differently ?

From: <glassfish_at_javadesktop.org>
Date: Wed, 07 Nov 2007 18:44:58 PST

1. NameAlreadyBoundException may have been caused by the fact that all your EJBs use the same default global jndi-name, since they have the same remote business interface. I suggest you use a sun-ejb-jar.xml to declare their global jndi-name:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
<enterprise-beans>
<ejb>
<ejb-name>FabToHubSenderSeattleSBean</ejb-name>
<jndi-name>FabToHubSenderSeattleSBean</jndi-name>
<resource-ref>
<res-ref-name>jms/FabZzzNnFactory</res-ref-name>
<jndi-name>jms/FabSeattleFactory</jndi-name>
</resource-ref>
<message-destination-ref>
<message-destination-ref-name>jms/FabZzzNnToHubQueue</message-destination-ref-name>
<jndi-name>jms/FabSeattleToHubQueue</jndi-name>
</message-destination-ref>
</ejb>
<ejb>
<ejb-name>FabToHubSenderHongKongSBean</ejb-name>
<jndi-name>FabToHubSenderHongKongSBean</jndi-name>
<resource-ref>
<res-ref-name>jms/FabZzzNnFactory</res-ref-name>
<jndi-name>jms/FabHongKongFactory</jndi-name>
</resource-ref>
<message-destination-ref>
<message-destination-ref-name>jms/FabZzzNnToHubQueue</message-destination-ref-name>
<jndi-name>jms/FabHongKongToHubQueue</jndi-name>
</message-destination-ref>
</ejb>
</enterprise-beans>
</sun-ejb-jar>

2. remove all annotations from your bean class, since you already use descriptors anyway. Why not keep the metadata in one place? Another reason is, with @Stateless annotation on bean class, you are declaring one extra EJB that you don't use.

3. In your java code, look up like this:
InitialContext ic = new InitialContext();
Queue queue = (Queue) ic.lookup("java:comp/env/jms/FabZzzNnToHubQueue");

4. Your ejb-jar.xml looks right. Make sure you add these <resource-ref> <message-destination-ref> for EACH EJB.

-cheng
[Message sent by forum member 'cf126330' (cf126330)]

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