[EJB 3.0] - Re: ClassCastExeption while invoking a Bean
by atul.iims2005
Dear Sir,
I am new to ejb, my problem is when i run my client program i get this error.
Anyone suggest me what i am doing wrong...........
This is my Exception which is generated during the client program execute.......
Exception in thread "main" java.lang.ClassCastException
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
at Client.main(Client.java:27)
Caused by: java.lang.ClassCastException: $Proxy0 cannot be cast to org.omg.CORBA.Object
at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)
... 2 more
Could anyone tell me what Iâm doing wrong? Thanks a lot. Looking forward to hearing from you.
These are my code..........
********remote interface*******
package My;
import java.rmi.*;
import javax.ejb.*;
public interface DemoInter extends EJBObject
{
public int add() throws RemoteException;
}
************home interface***********
package My;
import javax.ejb.*;
import java.rmi.*;
public interface DemoHome extends EJBHome
{
public DemoInter create(int a, int b) throws CreateException,RemoteException;
}
*************bean class*************
package My;
import javax.ejb.*;
import java.rmi.*;
public class DemoBean implements SessionBean
{
int a,b;
private SessionContext context;
public void setSessionContext(SessionContext ctx){this.context=ctx}
public void ejbCreate( int a,int b)
{
this.a=a;
this.b=b;
System.out.println("ejb Created");
}
public void ejbActivate(){System.out.println("ejbActivate()");}
public void ejbPassivate(){System.out.println("ejbPassivate()");}
public void ejbRemove(){System.out.println("distroyed");}
public int add() throws RemoteException
{
return(a+b);
}
}
***********my client**************
import java.util.*;
import javax.rmi.PortableRemoteObject;
import javax.naming.*;
import javax.rmi.*;
import My.*;
public class Client {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Properties properties=new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory");
properties.put("java.naming.provider.url","ejbd://localhost:4201");
Context ctx=new InitialContext(properties);
System.out.println("ic = " + ctx);
//MyTimeLocal myTimeLocal = (MyTimeLocal)context.lookup("java:comp/env/ejb/MyTimeBean");
// My.DemoInter remoteObj =(My.DemoInter)ctx.lookup("ejb/mgmt/MEJBRemoteHome");
Object object=ctx.lookup("ejb/mgmt/MEJBRemoteHome");
// System.out.println("hello" +object);
My.DemoHome ejbHome =(My.DemoHome)PortableRemoteObject.narrow(object,My.DemoHome.class);
System.out.println("hello" +ejbHome);
My.DemoInter obj1=ejbHome.create(4,5);
System.out.println(obj1.add());
} catch (Exception e) {
System.out.println(e);
// TODO: handle exception
}
}
}
this is log file..........
13:02:24,839 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
13:02:30,987 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
13:02:34,611 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
13:02:35,732 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
13:02:40,045 INFO [config] Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container)
13:02:40,045 INFO [config] Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container)
13:02:40,045 INFO [config] Configuring Service(id=Default BMP Container, type=Container, provider-id=Default BMP Container)
13:02:40,046 INFO [config] Configuring Service(id=Default CMP Container, type=Container, provider-id=Default CMP Container)
13:02:40,046 INFO [config] Configuring app: default/ejbsample1.jar/1207553559310/jar
13:02:40,078 INFO [OpenEJB] Auto-deploying ejb DemoEJB: EjbDeployment(deployment-id=ejbsample1.jar/DemoEJB)
13:02:40,079 INFO [config] Loaded Module: default/ejbsample1.jar/1207553559310/jar
13:02:40,976 INFO [startup] Assembling app: /home/atul/santemp/geronimo-tomcat6-javaee5-2.1/var/temp/geronimo-deployer17419.tmpdir/ejbsample1.jar
13:02:40,985 INFO [startup] Jndi(name=DemoEJBRemoteHome) --> Ejb(deployment-id=ejbsample1.jar/DemoEJB)
13:02:40,985 INFO [startup] Created Ejb(deployment-id=ejbsample1.jar/DemoEJB, ejb-name=DemoEJB, container=Default Stateless Container)
13:02:40,985 INFO [startup] Deployed Application(path=/home/atul/santemp/geronimo-tomcat6-javaee5-2.1/var/temp/geronimo-deployer17419.tmpdir/ejbsample1.jar)
13:02:41,083 INFO [SupportedModesServiceImpl] Portlet mode 'edit' not found for portletId: '/plugin.Deployment!227983155|0'
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4141982#4141982
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4141982
18 years
[JCA/JBoss] - DataSource.getConnection problem
by realvalkyrie
Thank U 4 all from beginning !!!!!!!
my code is below:
private InitialContext initial = null;
private DataSource dataSource = null;
public synchronized Connection getConnection(String name) {
try {
if(name==null) name = "";
initial = new InitialContext();
dataSource = (DataSource) initial.lookup("java:/jdbc/"+name);
Connection con = dataSource.getConnection();
return con;
} catch (SQLException e) {
System.out.print("can not get connection ...java:/jdbc/"+name);
System.out.println("SQLException cause ~~~"+e.getMessage());
e.printStackTrace();
return null;
} catch (NamingException e1) {
System.out.println("NamingException cause ~~~"+e1.getMessage());
e1.printStackTrace();
return null;
} finally{
try {
if(initial!=null) initial.close();
} catch (NamingException e) {
System.out.println("Error Closing InitialContext cause---->"+e.getMessage());
e.printStackTrace();
}
}
}
it always work perfect ,but sometimes the system will throw the follow Exception , this is the details:
INFO [STDOUT] can not get connection...java:/jdbc/et
ERROR [STDERR] java.sql.SQLException: JZ006: capture io exception :com.sybase.jdbc3.jdbc.SybConnectionDeadException: JZ0C0: the connection has already been closed .
here is my -ds.xml configuration
<no-tx-datasource>
<jndi-name>jdbc/et</jndi-name>
<connection-url>jdbc:sybase:Tds:127.0.0.1:2638?ServiceName=et</connection-url>
<driver-class>com.sybase.jdbc3.jdbc.SybDriver</driver-class>
<user-name>DBA</user-name>
< p a s s w o r d>**</ p a s s w o r d >
<idle-timeout-minutes>5</idle-timeout-minutes>
<blocking - timeout - millis>10000</blocking - timeout - millis>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.SybaseExceptionSorter</exception-sorter-class-name>
<min-pool-size>10</min-pool-size>
<max-pool-size>1000</max-pool-size>
<prepared-statement-cache-size>0</prepared-statement-cache-size>
<type-mapping>Sybase</type-mapping>
</no-tx-datasource>
help me please
thank u everyone !!!!!!!!!!!!
tips:
shoud i add this issue in the xml files to avoid that exception ?
<check-valid-connection-sql>some check sql</check-valid-connection-sql>
and make the initialcontext , datasource to static ?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4141970#4141970
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4141970
18 years