• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Strange error

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai I have a method in bean class called ejbFindAllUsers() which returns enumeration.
public Enumeration ejbFindAllUsers()
{

System.out.println("This is findallusers method .............");

Connection con = null;
PreparedStatement ps = null;
DBManager dbMan = null;
ResultSet resultSet = null;

Vector allUsers = new Vector();
try{ dbMan = new DBManager();

con = dbMan.getDBConnection();
ps = con.prepareStatement(sqlSelectAllsers);

resultSet = ps.executeQuery();

while(resultSet.next())
{
UserInfo userInfo1 = new UserInfo();
userInfo1.setUserID(resultSet.getString("USERID"));
userInfo1.setUserName(resultSet.getString("USERNAME"));
userInfo1.setUserRole(resultSet.getString("USERROLE"));

allUsers.addElement(userInfo1);
}



}catch (SQLException e){
status = ErrorCodes.KEY_NOT_FOUND_ERROR;
//throw new RemoteException(StaticMessage.getErrorMessage(status));
System.out.println("exception in allusers");
}
finally
{

try
{

if (resultSet != null)
resultSet.close();

if (ps != null)
ps.close();

if (con != null)
dbMan.closeConnection(con);
}catch(SQLException se)
{
System.out.println("Error in final of LOAD");
}
}

System.out.println("****************************************");
for(int i=0;i < allUsers.size();i++)
{

UserInfo info1 = new UserInfo();
info1=(UserInfo)allUsers.elementAt(i);

System.out.println("id is :"+info1.getUserID());
System.out.println("name is :"+info1.getUserName());
System.out.println("role is :"+info1.getUserRole());


}
return allUsers.elements();
}

}
return allUsers.elements();
}
I have written a Testclient .I am trying to display the data

TestUser.java

java.util.Enumeration infoEnum = home.findAllUsers();
for(int i=0;infoEnum.hasMoreElements();i++)
{
System.out.println(i+"th record is.............");
UserInfo userInfo1 = new UserInfo();
System.out.println("enum elment is........"+((UserInfo)infoEnum.nextElement()).getUserID());
userInfo1= (UserInfo)infoEnum.nextElement();

System.out.println("id is :"+userInfo1.getUserID());
System.out.println("name is :"+userInfo1.getUserName());
System.out.println("role is :"+userInfo1.getUserRole());


System.out.println("End of "+ i+ " record ........");

}
I am getting a strange exception
java.lang.ClassCastException: com.proteomics.sequoia.ejb.UserBeanEOImpl_WLStub
at com.proteomics.sequoia.ejb.TestUser.main(TestUser.java:38)
---------------
Can anybody tell me the answer ?

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is probably one of these lines that is throwing the ClassCastException:
info1=(UserInfo)allUsers.elementAt(i);
userInfo1= (UserInfo)infoEnum.nextElement();
I recommend you do some debugging to make sure that the Vector allUsers does not contain any non-UserInfo types. If it's not that you might need to post some more code
 
greg philpott
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about my last post please ignore it and read this:


A common problem when deploying and using EJBs and servlets is the ClassCastException. ClassCastExceptions can occur when a class of the same name resides in more than one classloader within WebLogic Server. Although the classes may have the same name and use the same bytecode, if the classes are loaded by separate classloaders, they are treated as different classes. A common scenario is as follows:

An EJB provider uses a support class, "Address" in an EJB's public interface. Upon deployment, the EJB classloader exports the EJB's public interface, and also exports the "Address" class, to the WebLogic classloader.
A servlet developer includes an identical "Address" class as part of a servlet deployment. When the servlet class is deployed, the servlet classloader loads and maintains an identical version of the "Address" class.
The servlet invokes the EJB to obtain a new object of the "Address" class. In this case, WebLogic Server yields a ClassCastException error. Because the "Address" class exists in both the WebLogic classloader and Servlet classloader, they are treated as completely different classes.
To correct such ClassCastException errors, EJB and servlet developers must ensure that no two classloaders ever load an identical class. Specifically, you should always ensure that EJB classes reside only in the deployed EJB .jar file or EJB directory, and that they are not included in other EJB .jar files or classpath definitions.

 
shivani reddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried to print enumeration in my bean.It's printing fine there.prob is in my client
(infoEnum.nextElement().getClass().getName() )
is printing as
com.proteomics.sequoia.ejb.TestUserBeanEOImpl_WLStub
Java gurus help me
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi shivani,
what's the primary key class for the entity bean,
is UserInfo a entity bean? if it's entity bean then u cannot directly return as a enumeration list! instead u should return enumeration containing the primary key class. if the primary key class is not defined then pass the enumeration of the primary key
in this case it should be userid( String),
u should add userid to the vector. and then return it's enumeration.
Hope ur probs is solved
best of luck
------------------
Praveen Kumar Mathaley
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
Master Gardener Program
https://coderanch.com/t/771761/Master-Gardener-Program
reply
    Bookmark Topic Watch Topic
  • New Topic