[jboss-user] [JNDI/Naming/Network] - JNDI EJB local lookup is ok, but the bean cannot be invoked
j2ee4cxw
do-not-reply at jboss.com
Thu Jun 26 12:58:41 EDT 2008
We are building application based on Struts 2 and EJB 3. The server we use is JBOSS 4.2.2 GA. In the struts action class, we try to save data to database via ejb session bean. When the ejb was obtained via jndi romote look up, everything is fine. The bean is found and data is saved. However, when we do a local jndi lookup, the bean is found, but upon invoking the bean JBOSS threw following error:
javax.ejb.EJBException: java.lang.IllegalArgumentException: Wrong target. class com.boeing.he.bessy.bean.ShipperManagerBean for public long com.boeing.he.bessy.bean.ShipperManagerBean.createShipper(com.boeing.he.bessy.domain.Shipper) throws com.boeing.he.bessy.exception.BessyException.
This has happened to three of our developers with different beans. The bottom line is the local lookup is succeful, but the bean cannot be invoked. Any kind of suggestion is greatly appreciated. Thanks. Here are our codes:
////This is the save method of our Struts action class/////
public String save()
{
try
{
//Shipper(spr) is our entity.
com.boeing.he.bessy.domain.Shipper spr = new com.boeing.he.bessy.domain.Shipper();
spr.setManifest("ABC");
spr.setSite("PHL100");
spr.setLocation("PHL");
spr.setDocTypeCode("DOC100");
//remote call. WORKS!
// String SHIPPER_JNDI_NAME = "BessyEAR/ShipperManagerBean/remote";
// Object ref1 = ServiceLocator.getEJB(SHIPPER_JNDI_NAME);//jndi lookup
// ShipperManagerRemote smbean1 = (ShipperManagerRemote)ref1;
// long shipperId1 = smbean1.createShipper(spr);
// setMessage("Shipper Created with Id:" + shipperId1);
//local call. Errors
String SHIPPER_JNDI_NAME = "BessyEAR/ShipperManagerBean/local";
Object ref2 = ServiceLocator.getEJB(SHIPPER_JNDI_NAME);//jndi lookup
ShipperManagerLocal smbean2 = (ShipperManagerLocal) ref2;
long shipperId2 = smbean2.createShipper(spr); ////<==ERROR OCURRED ON THIS LINE. ERROR OCURRED ON THIS LINE
setMessage("Shipper Created with Id:" + shipperId2);
}
catch(Exception ex)
{
log.error(ex);
setMessage("some error occurred");
}
return SUCCESS;
}
///Interfaces////////
public interface IShipperManager {
public long createShipper(Shipper shipper) throws BessyException;
}
@Local
public interface ShipperManagerLocal extends IShipperManager{}
@Remote
public interface ShipperManagerRemote extends IShipperManager {}
////The EJB session bean/////////
@Stateless
public class ShipperManagerBean implements ShipperManagerLocal,ShipperManagerRemote {
@PersistenceContext(unitName="BessyPU")
private EntityManager manager;
public long createShipper(Shipper shipper) throws BessyException
{
manager.persist(shipper);
return shipper.getShipperId();
}
}
////ServiceLocator///////
public static Object getEJB(String jndiName) {
Object object = null;
try {
InitialContext ctx = new InitialContext();
object = ctx.lookup(jndiName);
} catch (Exception e) {
e.printStackTrace();
}
return object;
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4160940#4160940
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4160940
More information about the jboss-user
mailing list