-
1. Re: Pl help how to Remove & update using BMP
adrian.brock Aug 17, 2003 11:08 AM (in response to shanker)You aren't going to get many answers if you don't
post the exception or the code that is wrong.
Regards,
Adrian -
2. RE: Pl help me. How to do Remove & update using BMP
shanker Aug 19, 2003 7:14 AM (in response to shanker)Here is the code and error. Please help me. Thankyou very much in advance. Please also tell me how to do for update.
This is my EJBLocalHome
package com.ami.amihr;
import javax.ejb.FinderException;
import javax.ejb.CreateException;
import java.util.Collection;
import javax.ejb.*;
import com.ami.amihr.EmployeeVO;
import com.ami.amihr.EmployeeLocal;
public interface EmployeeHomeLocal extends javax.ejb.EJBLocalHome
{
public EmployeeLocal create(EmployeeVO tempObject) throws CreateException;
public EmployeeLocal findByPrimaryKey(Integer primarykey) throws FinderException;
public void remove();
public Collection findAll() throws FinderException;
}
Here is my bean's ejbRemove
public void ejbRemove()
{
Connection con = null;
PreparedStatement ps = null;
ResultSet result = null;
Integer primaryKey = (Integer)context.getPrimaryKey();
try
{
con = this.getConnection();
ps = con.prepareStatement("delete from Employee where employeeId = ?");
ps.setInt(1, employeeId.intValue());
if(ps.executeUpdate() != 1)
{
throw new EJBException("ejbRemove");
}
}
catch(SQLException se)
{
throw new EJBException(se);
}
finally
{
try
{
if(ps != null) ps.close();
if(con != null) con.close();
}
catch(SQLException se)
{
se.printStackTrace();
}
}
}
Here is the error during deployment.
Bean : Employee
Method : public abstract void remove()
Section: 12.2.11
Warning: Each local home method must match a method defined in the entity bean c
lass.
18:11:09,343 ERROR [MainDeployer] could not create deployment: file:/G:/uma/jbos
s/jboss-3.2.0_tomcat-4.1.24/server/default/tmp/deploy/server/default/deploy/outp
ut.ear/46.output.ear-contents/output.jar
org.jboss.deployment.DeploymentException: Verification of Enterprise Beans faile
d, see above for error messages.
at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:501)
at org.jboss.deployment.MainDeployer.create(MainDeployer.java:784)
at org.jboss.deployment.MainDeployer.create(MainDeployer.java:776)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:639)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:613)
at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBea
nDispatcher.java:284)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:549) -
3. Re: RE: Pl help me. How to do Remove & update using BMP
adrian.brock Aug 19, 2003 8:59 AM (in response to shanker)remove() is already defined in EJBLocalHome using the
correct signature.
Regards,
Adrian -
4. Re: Pl help how to Remove & update using BMP
shanker Aug 25, 2003 7:49 AM (in response to shanker)Thank you very much. It works now.
-
5. Re: Pl help how to view all the records using ejbFindAll (B
shanker Aug 25, 2003 7:54 AM (in response to shanker)Hi, I am new to jboss and EJB. I am not able to view the records using find all. Please help me. Thanks in advance. I have marked problematic line. Thanks again.
Error
18:48:11,656 INFO [Engine] StandardWrapper[/ums:default]: Loading container ser
vlet default
18:48:11,718 INFO [Engine] StandardWrapper[/ums:invoker]: Loading container ser
vlet invoker
18:48:11,812 INFO [MainDeployer] Deployed package: file:/G:/uma/jboss/jboss-3.2
.0_tomcat-4.1.24/server/default/deploy/output.ear
18:48:27,890 INFO [STDOUT] lookup success Employee
18:48:27,906 ERROR [STDERR] java.lang.ClassCastException
18:48:27,906 ERROR [STDERR] at org.apache.jsp.EmployeeView_jsp._jspService(E
mployeeView_jsp.java:76)
18:48:27,906 ERROR [STDERR] at org.apache.jasper.runtime.HttpJspBase.service
(HttpJspBase.java:137)
18:48:27,906 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:853)
18:48:27,906 ERROR [STDERR] at org.apache.jasper.servlet.JspServletWrapper.s
ervice(JspServletWrapper.java:210)
18:48:27,906 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.serviceJ
spFile(JspServlet.java:295)
18:48:27,906 ERROR [STDERR] at org.apache.jasper.servlet.JspServlet.service(
JspServlet.java:241)
18:48:27,906 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpSe
rvlet.java:853)
Bean code
public Collection ejbFindAll() throws FinderException
{
Connection con = null;
PreparedStatement ps = null;
ResultSet result = null;
ArrayList objectList = new ArrayList();
Integer employeeId;
try
{
con = this.getConnection();
ps = con.prepareStatement("select * from Employee "); result = ps.executeQuery();
while(result.next())
{
employeeId = (Integer) result.getObject("employeeId");
objectList.add(employeeId);
}
return objectList;
}
catch(SQLException se)
{
throw new EJBException(se);
}
finally
{
try
{
if(result != null) result.close();
if(ps != null) ps.close();
if(con != null) con.close();
}
catch(SQLException se)
{
se.printStackTrace();
}
}
}
}
<%@ page import="java.sql.Date,java.io.*,java.sql.*,javax.naming.InitialContext,
javax.naming.Context,java.util.Properties, javax.rmi.PortableRemoteObject, java.text.SimpleDateFormat,javax.ejb.EJBHome,
java.util.Collection, java.util.*, com.ami.amihr.EmployeeHomeLocal, com.ami.amihr.EmployeeLocal,
com.ami.amihr.EmployeeVO;" %>
<h2 align='center'> Employee Details </h2>
<%
EmployeeHomeLocal localHome;
EmployeeLocal employeeLocal;
try
{
Object object;
Context jndiContext = new InitialContext();
localHome = (EmployeeHomeLocal) jndiContext.lookup("java:comp/env/ejb/EmployeeHomeLocal");
System.out.println("lookup success Employee");
Collection tempEmployeeValueObjects;
try
{
tempEmployeeValueObjects = localHome.findAll();
Iterator iterator=tempEmployeeValueObjects.iterator();
while(iterator.hasNext())
{
THIS Line has problem->Integer tempEmployeeId= (Integer) iterator.next();
try
{
employeeLocal = localHome.findByPrimaryKey(tempEmployeeId);
System.out.println (
"employeeId" + employeeLocal.getEmployeeId() +
"employeeFirstName" + employeeLocal.getEmployeeFirstName() +
"employeeLastName" + employeeLocal.getEmployeeLastName() +
"employeeEmailId" + employeeLocal.getEmployeeEmailId() +
"dateOfJoining" + employeeLocal.getDateOfJoining() +
"dateOfBirth" + employeeLocal.getDateOfBirth() +
"isEmployeeNow" + employeeLocal.getIsEmployeeNow() +
"isPermanent" + employeeLocal.getIsPermanent() +
"isOnContract" + employeeLocal.getIsOnContract() +
"isOnProbation" + employeeLocal.getIsOnProbation());
}
catch(javax.ejb.FinderException fe)
{
fe.printStackTrace();
}
}
}
catch(javax.ejb.FinderException fe)
{
fe.printStackTrace();
System.out.println("Object not found for view");
}
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("unable to get handle for Employee");
}
%>