JNDI Lookup Failure, ClassCastException, 4.0.4RC1
tromanowski Mar 17, 2006 3:22 PMProblem: I'm getting a java.lang.ClassCastException in my server log when I try when I try to perform a JNDI lookup.
The error is much like the one here found by khooke here: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=79130
Actually, I am encountering what may be a few problems, but am going to try and go from the top. I've searched forums for days and I have the feeling that my problem is a common one, but so far all the standard solutions aren't working. I've read the ejb 3.0 simplified and persistence specs (pfd), wiki's and forums, but I am new to EJB 3.0 and fear I am overlooking the obvious.
I'm running jboss 4.0.4RC1 and installed the ejb 3.0 libs via the installer.
I'm running Myfaces 1.1.1 with Beehive pageflows, and oracle 10g as my database. I've tested my war file separately to verify that is not causing me problems. My problem is only encountered when I try to access an entity bean (well, when I try to perform a JNDI lookup).
Regarding the other posting above, my persistence.xml file looks like:
<?xml version="1.0" encoding="UTF-8"?> <persistence> <persistence-unit name="requirements"> <jta-data-source>java:/OracleDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/> </properties> </persistence-unit> </persistence>
My EJBs are reside in their own jar file, and are built into an ear. My persistence.xml file is placed within the META-INF directory of the EJB jarfile.
InitialContext ic = new InitialContext(); rm = (RequirementsManagerBean)ic.lookup( "alpha/RequirementsManagerBean/local" );
From the RC3 to RC4 upgrade guide (this still applies, no?), "If you deploy EJBs within an EAR, then the default JNDI name is the same, except the base name is prepended to the default JNDI name. For example, if it is foo.ear then the default names would be foo/EJBNAME/remote and foo/EJBNAME/local". My ear name is "alpha".
My datasource appears to be configured correctly because i see it connected via the jmx-console, and a "MyTableEntity" test entity EJB I created causes a "mytable" table to be created in my oracle database.
In my Global JNDI namespace, the following is listed:
java: Namespace +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory) +- DefaultDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource) +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory) +- OracleDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource) +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter) +- comp (class: javax.naming.Context) +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl) +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory) +- jaas (class: javax.naming.Context) | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext) | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext) | +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext) +- timedCacheFactory (class: javax.naming.Context) Failed to lookup: timedCacheFactory, errmsg=org.jboss.util.TimedCachePolicy +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory) +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory) +- comp.ejb3 (class: javax.naming.Context) | NonContext: null +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter) +- TransactionManager (class: org.jboss.tm.TxManager) Global JNDI Namespace +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory) +- TopicConnectionFactory (class: org.jboss.naming.LinkRefPair) +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef) +- UserTransactionSessionFactory (proxy: $Proxy27 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory) +- alpha (class: org.jnp.interfaces.NamingContext) | +- RequirementsManagerBean (class: org.jnp.interfaces.NamingContext) | | +- local (proxy: $Proxy71 implements No ClassLoaders found for: com.test.gems.requirements.RequirementsManagerInterface (no security manager: RMI class loader disabled)) | +- MyTableManager (class: org.jnp.interfaces.NamingContext) | | +- local (proxy: $Proxy69 implements No ClassLoaders found for: com.test.gems.requirements.MyTableInterface (no security manager: RMI class loader disabled))
So it looks like JNDI binding is my problem, but here is what I _really_ don't get: I only have a problem when my Local Stateless bean calls
return this.em.find(RequirementsEntity.class, 1);
(I have a test record in the table with a primary key of 1.)
If I don't attempt to call this method, and call another one which returns a string from the same Local Stateless bean, my jsp page renders correctly and displays the value returned by the bean's method. I _do_, however, still get the ClassCastException on my JNDI lookup (makes sense, considering the Global JNDI listing shows the bean as not bound).
Entity bean:
@Entity @Table(name="requirements") public class RequirementsEntity implements java.io.Serializable { public RequirementsEntity(){} public RequirementsEntity( String name, String description ) { this.name = name; this.description = description; } @Id // at GeneratedValue(strategy=GenerationType.AUTO) public int getEr_Id() { return er_Id; } public void setEr_Id(int er_Id){ this.er_Id = er_Id; ... et. al. ... }
Snippet of the Stateless bean:
@Stateless @Local(RequirementsManagerInterface.class) public class RequirementsManagerBean implements RequirementsManagerInterface { private String name = "A test jsp can access this attribute just fine via a method after the bean is looked up"; /** * Create an EntityManager to use with our Entity Beans */ @PersistenceContext(unitName = "requirements") protected EntityManager em;
Just for kicks, I also attempted a context lookup using "alpha/requirements/RequirementsManagerBean/local" and that produced the same errors.
Related Questions:
Is my injection incorrect?
Do I need to explicitly list the beans I am accessing via the property in persistence.xml? From the RC5 tutorials and the spec, it looks like that is not necessary, but I am not clear on when such usage is necessary (to avoid name collisions?).
Does jboss 4.0.4RC1 include the EJB3.0 RC5-PDF libs? The date on the 4.0.4RC1 jars is newer than the EJB3.0 RC5-PDF libs, and I see other postings suggesting that 4.0.4RC1 includes these, but it is not clear.
When I have a pre-exising table in my database and then deploy my ear, hibernate attempts to alter the pre-existing table, failing each time (even though I've set my "hibernate.hbm2ddl.auto" property to "update." This may be normal hibernate behavior, and is more of a hibernate question, but i'll throw it out there if anyone would like to answer.
Is there something inherently wrong with my find call?
Sorry for the long post, just wanted to provide as much info on the prolbem as possible. I'm also putting together notes for a tutorial on things I found to be unclear from the current docs, so I welcome any tertiary info.