javax.naming.NamingException: Could not dereference object -
htran_888 Feb 19, 2007 4:32 PMHi All,
I am receiving the following error when trying to reference 2 Stateful Session beans (TransactionPersistenceContext & ExtendedPersistenceContext):
-------------------------------------------------------------------------
Distributing D:\Test\EJB3ex511-client\dist\EJB3ex511-client.jar to [org.jboss.deployment.spi.LocalhostTarget@13aaba1]
Deploying D:\Test\EJB3ex511-client\dist\EJB3ex511-client.jar
Deploying D:\Test\EJB3ex511-client\dist\EJB3ex511-client.jar
Applicaton Deployed
Operation start started
Operation start completed
run-deploy:
run-tool:
run-jar:
log4j:WARN No appenders could be found for logger (org.jboss.security.SecurityAssociation).
log4j:WARN Please initialize the log4j system properly.
no cabin should be null: null
Master Suite
1
1
3
Updating detached cabin instance with new bed count of 4
Finding cabin to see it has been updated with a merge() on server
new bed count is: 4
javax.naming.NamingException: Could not dereference object [Root exception is java.lang.reflect.UndeclaredThrowableException]
at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1150) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:705)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at ejb3ex511client.Main.main(Main.java:50)
Caused by: java.lang.reflect.UndeclaredThrowableException
at $Proxy1.createProxy(Unknown Source)
at org.jboss.ejb3.JndiProxyFactory.getObjectInstance(JndiProxyFactory.java:52)
-------------------------------------------------------------------------------
Here are the codes for 1 Stateless (TravelAgentBean - pre-requisite) & 1 Stateful (TransactionPersistenceContextBean) session beans and a Client manipulating these beans:
@Stateless public class TravelAgentBean implements TravelAgentRemote { @PersistenceUnit(unitName="EJB3ex51") private EntityManagerFactory factory; @PersistenceContext(unitName="EJB3ex51") private EntityManager manager; public void createCabin(Cabin cabin) { manager.persist(cabin); } public Cabin findCabin(int pKey) { return manager.find(Cabin.class, pKey); } public void updateCabin(Cabin cabin) { manager.merge(cabin); }
@Stateful public class TransactionPersistenceContextBean implements TransactionPersistenceContextRemote { @PersistenceContext(unitName="titan", type=PersistenceContextType.TRANSACTION) private EntityManager manager; private Cabin cabin; public void setCabin(int pk) { cabin = manager.find(Cabin.class, pk); } public void updateBedCount(int newBedCount) { cabin.setBedCount(newBedCount); } @Remove public void remove() { } }
public static void main(String[] args) { try { Context jndiContext = getInitialContext(); Object ref = jndiContext.lookup("travelagent.TravelAgentRemote"); TravelAgentRemote dao = (TravelAgentRemote)ref; Cabin noCabin = dao.findCabin(1); System.out.println("no cabin should be null: " + noCabin); Cabin cabin_1 = new Cabin(); cabin_1.setId(1); cabin_1.setName("Master Suite"); cabin_1.setDeckLevel(1); cabin_1.setShipId(1); cabin_1.setBedCount(3); dao.createCabin(cabin_1); Cabin cabin_2 = dao.findCabin(1); System.out.println(cabin_2.getName()); System.out.println(cabin_2.getDeckLevel()); System.out.println(cabin_2.getShipId()); System.out.println(cabin_2.getBedCount()); System.out.println("Updating detached cabin instance with new bed count of 4"); cabin_2.setBedCount(4); dao.updateCabin(cabin_2); System.out.println("Finding cabin to see it has been updated with a merge() on server"); Cabin cabin_3 = dao.findCabin(1); System.out.println("new bed count is: " + cabin_3.getBedCount()); ref = jndiContext.lookup("travelagent.TransactionPersistenceContextRemote"); TransactionPersistenceContextRemote txBean = (TransactionPersistenceContextRemote)ref; Cabin fetchedCabin = dao.findCabin(1); int oldBedCount = fetchedCabin.getBedCount(); System.out.println("Set up transaction persistence context stateful bean"); txBean.setCabin(1); txBean.updateBedCount(5); fetchedCabin = dao.findCabin(1); System.out.println("Cabin bed count will still be " + oldBedCount + ": " + fetchedCabin.getBedCount()); System.out.println("Set up extended persistence context stateful bean"); ref = jndiContext.lookup("travelagent.ExtendedPersistenceContextRemote"); ExtendedPersistenceContextRemote extendedBean = (ExtendedPersistenceContextRemote)ref; extendedBean.setCabin(1); extendedBean.updateBedCount(5); fetchedCabin = dao.findCabin(1); System.out.println("Cabin bed count will be 5: " + fetchedCabin.getBedCount()); // cleanup txBean.remove(); extendedBean.remove(); } catch (javax.naming.NamingException ne) { ne.printStackTrace(); } } public static Context getInitialContext() throws javax.naming.NamingException { return new javax.naming.InitialContext(); }
I have tried to split the client into separate classes but the outcome is still the same.
I am running Netbeans 5.5, JBoss 4.0.5 AS on Windows XP platform.
I have struggled with this issue for many days after trying different method of deployment including using both sun-appserver-pe9.0 & JBoss 4.0.5 AS without success.
This exercise is from workbook (ex05_1), title EJB 3.0 by Bill Burke.
Any assistance would be very much appreciated.
Thanks,
Henry