aspose file tools*
The moose likes JBoss/WildFly and the fly likes Problem about ejbFindAll() of my BMP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Problem about ejbFindAll() of my BMP" Watch "Problem about ejbFindAll() of my BMP" New topic
Author

Problem about ejbFindAll() of my BMP

Ivan
Greenhorn

Joined: Jul 25, 2005
Posts: 10
Hi All,
I'm having a problem when calling the findAll() method for my bmp bean.
Seems the class type returned by the findAll() method is not what I expect. I use lomboz eclipse to generate my code, Jboss4.0.2 to run my program and MYSQL4 as my db.
Here is the abstract of my bmp and jsp calling program.

[bmp]
.....
public java.util.Collection ejbFindAll() {
Vector vector = new Vector();
DataSource dataSource = getDataSource();
Connection connection = null;
PreparedStatement statement = null;
ResultSet result;
TrackingData tracking = null;
try {
connection = dataSource.getConnection();
statement = connection.prepareStatement("SELECT catid, docid, trackdate FROM Tracking");
result = statement.executeQuery();
while(result.next()) {
tracking = new TrackingData();
tracking.setCatid(result.getString(1));
tracking.setDocid(result.getString(2));
tracking.setTrackdate(result.getDate(3));
vector.add(tracking);
}
result.close();
return vector;
} catch (Exception se) {
throw new EJBException("Could not find record from DB: "
+ se.getMessage()+ se.getStackTrace());
} finally {
try {
statement.close();
connection.close();
} catch (Exception e) {}
}
}
......

[jsp]
......
<%
try {
//Lookup User Home interface
Context context = new InitialContext();
Object ref = context.lookup("ejb/Tracking");
TrackingHome trackingHome = (TrackingHome)
PortableRemoteObject.narrow(ref, TrackingHome.class);

Collection bean ;
Iterator iterator ;
TrackingData trackingData;
String catid;
String docid;
Date trackDate;
try {
bean = trackingHome.findAll();
iterator = bean.iterator();
while(iterator.hasNext()) {
trackingData = (TrackingData)iterator.next(); <--- throw Exception here
catid = trackingData.getCatid();
docid = trackingData.getDocid();
trackDate = trackingData.getTrackdate();
out.println("<br>");
out.println("Catid:"+catid+" ");
out.println("Docid:"+docid+" ");
out.println("Trackdate:"+trackDate+"\n");
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace(System.out);
}
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println(e.getStackTrace());
}
%>

......
There is an object returned by the remote 'findAll()' function.
However, when I call "trackingData = (TrackingData)iterator.next();", it throws "java.lang.ClassCastException: $Proxy109"

Here is the error message details,
$Proxy109
java.lang.ClassCastException: $Proxy109
at org.apache.jsp.TestTracking_jsp._jspService(org.apache.jsp.TestTracking_jsp:79)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
1at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)


Do you have any ideas ? please kindly help.


Ivan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem about ejbFindAll() of my BMP