Hi there,
I am facing problem in removing cmp beans. When ever I tried to remove a
cmp it throws IllegalArgumentException i.e.
javax.transaction.TransactionRolledbackException: Load failed;
nested exception is:
java.lang.IllegalArgumentException; nested exception is: java.rmi.ServerException: Load failed; nested exception is: java.lang.IllegalArgumentException but this happened only in case when I have my own primary key
class. If I have java class as a primary key, removing of bean cause
no problem but when I declare my own primary key class it throws exception. If
any body have tried this scenario on jboss 2.4.6 then let me know his
findings.
I am using Jboss version 2.4.6 the tomcat
4.0.3, jdk is 1.4., SQLServer 2000 with Microsoft jdbc driver, OS
windows NT and the client I have tried are either jsps, servlets or
session beans in all three cases problem remains same, I am attaching the
code of the home, remote, bean and primary key classes, deployment descriptor
and pasting it in mail too the exception is also there at the bottom as u can
see in client code I first find the remote obj through fBPK then access the bean
remote method so far so good then I call remove over remote object, here
is the exception occures that I pasted in the bottom. I have also added the
table script so now I think every thing is here to check it out.
I have posted this problem earlier too and tried some suggested solutions
but problem remains there.
Nayyer Kamran
CREATE TABLE [dbo].[Application] ( [AppID] [int] NOT NULL , [AppDesc] [char] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ) ON [PRIMARY] primary key class
public class ApplicationPK implements Serializable
{
public Integer
appID;
public ApplicationPK()
{
appID = new Integer(0); } public ApplicationPK(Integer
appID) {
this.appID = appID; } public boolean equals(Object
obj) {
if (this.getClass().equals(obj.getClass())) { ApplicationPK that = (ApplicationPK) obj; return this.appID.intValue() == that.appID.intValue(); } return false; } public int hashCode()
{
return appID.intValue(); } public String
toString(){
return appID.toString(); } } Home Interface
public interface ApplicationHome extends EJBHome
{
public Application create(Integer appID, String appDesc) throws RemoteException, CreateException; public Application create(Integer appID) throws RemoteException, CreateException; public Application findByPrimaryKey(ApplicationPK primaryKey) throws RemoteException, FinderException; public Collection findAll() throws RemoteException, FinderException; } Remote Interface
public interface Application extends EJBObject
{
public Integer getAppID() throws RemoteException; public String getAppDesc() throws RemoteException; public void setAppDesc(String appDesc) throws RemoteException; } Bean Class
public class ApplicationBean implements EntityBean
{
EntityContext entityContext; public Integer appID; public String appDesc; public ApplicationPK ejbCreate(Integer appID, String appDesc) throws CreateException { this.appID = appID; this.appDesc = appDesc; return null; } public ApplicationPK ejbCreate(Integer appID) throws CreateException { return ejbCreate(appID, null); } public void ejbPostCreate(Integer appID, String appDesc) throws CreateException { } public void ejbPostCreate(Integer appID) throws CreateException { ejbPostCreate(appID, null); } public void ejbLoad() { } public void ejbStore() { } public void ejbRemove(){ System.out.println("here to remove comp"); } public void ejbActivate() { } public void ejbPassivate() { } public void setEntityContext(EntityContext entityContext) { this.entityContext = entityContext; } public void unsetEntityContext() { entityContext = null; } public Integer getAppID() { return appID; } public String getAppDesc() { return appDesc; } public void setAppDesc(String appDesc) { this.appDesc = appDesc; } } ejbjar.xml
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" "http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd"> <ejb-jar> <enterprise-beans> <entity> <ejb-name>ApplicationCOMP</ejb-name> <home>com.cst.pps.ejbs.cmp.tmpcomp.ApplicationHome</home> <remote>com.cst.pps.ejbs.cmp.tmpcomp.Application</remote> <ejb-class>com.cst.pps.ejbs.cmp.tmpcomp.ApplicationBean</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>com.cst.pps.ejbs.cmp.tmpcomp.ApplicationPK</prim-key-class> <reentrant>False</reentrant> <cmp-field> <field-name>appID</field-name> </cmp-field> <cmp-field> <field-name>appDesc</field-name> </cmp-field> <resource-ref> <res-ref-name>jdbc/PPSDS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> </entity> </enterprise-beans> <assembly-descriptor> <container-transaction> <method> <ejb-name>ApplicationCOMP</ejb-name> <method-name>*</method-name> </method> <trans-attribute>Required</trans-attribute> </container-transaction> </assembly-descriptor> </ejb-jar> jboss.xml
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC '-//JBoss//DTD JBOSS 2.4//EN' 'http://www.jboss.org/j2ee/dtd/jboss_2_4.dtd'> <jboss> <enterprise-beans> <entity> <ejb-name>ApplicationCOMP</ejb-name> <jndi-name>TempComp</jndi-name> <resource-ref> <res-ref-name>jdbc/PPSDS</res-ref-name> <jndi-name>java:/PPSDS</jndi-name> </resource-ref> </entity> </enterprise-beans> </jboss> jaws.xml
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE jaws PUBLIC '-//JBoss//DTD JAWS 2.4//EN' 'http://www.jboss.org/j2ee/dtd/jaws_2_4.dtd'> <jaws> <enterprise-beans> <entity> <ejb-name>ApplicationCOMP</ejb-name> <cmp-field> <field-name>appID</field-name> <column-name>AppID</column-name> </cmp-field> <cmp-field> <field-name>appDesc</field-name> <column-name>AppDesc</column-name> </cmp-field> <finder> <name>findAll</name> <query></query> <order></order> </finder> <table-name>Application</table-name> </entity> </enterprise-beans> </jaws> Test client jsp (just put code snipet in
jsp, client will be there u may need to add some more debug
messages)
Object obj =
cont.lookup("TempComp");
ApplicationHome home = (ApplicationHome)PortableRemoteObject.narrow(obj,ApplicationHome.class); if(request.getParameter("opt").equals("1")){ home.create(new Integer(15),"My Application Comp"); } else if(request.getParameter("opt").equals("0")){ Application app = home.findByPrimaryKey(new ApplicationPK(new Integer(15))); out.println(((ApplicationPK)app.getPrimaryKey()).toString()); out.println(app.getAppDesc()); System.out.println("removing from home"); home.remove(app.getHandle()); } else if(request.getParameter("opt").equals("2")){ Application app = home.findByPrimaryKey(new ApplicationPK(new Integer(2))); out.println(app.getAppDesc()); } } catch(NamingException ex){ System.out.println("tmperror"+ex.toString()+ex.getMessage()+ex.getCause()); ex.printStackTrace(); } catch(RemoveException ex){ System.out.println("tmperror"+ex.toString()+ex.getMessage()+ex.getCause()); ex.printStackTrace(); } catch(RemoteException ex){ System.out.println("tmperror"+ex.toString()+ex.getMessage()+ex.getCause()); ex.printStackTrace(); } catch(CreateException ex){ System.out.println("tmperror"+ex.toString()+ex.getMessage()+ex.getCause()); ex.printStackTrace(); }
|