Should entities bind to JNDI?
culli Jan 21, 2009 5:21 PMWhen I deployed an entity with EJB2/xdoclet I could specify a local-jndi-name in @ejb.bean and it would bind to a JNDI name.
How do I do this with EJB 3 annotations? I'm using JBoss 4.2.3GA with no modifications and the first jboss example code from Enterprise JavaBeans 3.0 (Bill Burke/Richard Monson-Haefel). Very basic stuff. I can run the test client just fine.
I'm checking the JNDIView bean for the Cabin bean and it's not there, but I can see the TravelAgent session bean. At some point I need to be able to look up my EJB 3 beans from legacy EJB 2 stuff that won't be converted (at least not within a year or so), so doesn't the EJB 3 entity need to be bound in JNDI?
JNDI View Global:
+- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair) +- jmx (class: org.jnp.interfaces.NamingContext) | +- invoker (class: org.jnp.interfaces.NamingContext) | | +- RMIAdaptor (proxy: $Proxy47 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt) | +- rmi (class: org.jnp.interfaces.NamingContext) | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef) +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory) +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory) +- UserTransactionSessionFactory (proxy: $Proxy15 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory) +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory) +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory) +- TransactionSynchronizationRegistry (class: com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple) +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction) +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef) +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef) +- persistence.units:jar=titan.jar,unitName=titan (class: org.hibernate.impl.SessionFactoryImpl) +- queue (class: org.jnp.interfaces.NamingContext) | +- A (class: org.jboss.mq.SpyQueue) | +- testQueue (class: org.jboss.mq.SpyQueue) | +- ex (class: org.jboss.mq.SpyQueue) | +- DLQ (class: org.jboss.mq.SpyQueue) | +- D (class: org.jboss.mq.SpyQueue) | +- C (class: org.jboss.mq.SpyQueue) | +- B (class: org.jboss.mq.SpyQueue) +- topic (class: org.jnp.interfaces.NamingContext) | +- testDurableTopic (class: org.jboss.mq.SpyTopic) | +- testTopic (class: org.jboss.mq.SpyTopic) | +- securedTopic (class: org.jboss.mq.SpyTopic) +- console (class: org.jnp.interfaces.NamingContext) | +- PluginManager (proxy: $Proxy48 implements interface org.jboss.console.manager.PluginManagerMBean) +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef) +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory) +- TravelAgentBean (class: org.jnp.interfaces.NamingContext) +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef) +- QueueConnectionFactory (class: org.jboss.naming.LinkRefPair) +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
Cabin.java
package com.titan.domain; import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Column; import javax.persistence.Id; import org.jboss.annotation.ejb.LocalBinding; @Entity @Table(name="CABIN") public class Cabin implements java.io.Serializable { private int id; private String name; private int deckLevel; private int shipId; private int bedCount; @Id @Column(name="ID") public int getId() { ...
persistence.xml
<persistence> <persistence-unit name="titan"> <jta-data-source>java:/DefaultDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="create-drop"/> </properties> </persistence-unit> </persistence>