ramand singh

Greenhorn
+ Follow
since Jul 05, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by ramand singh

Thanks

It works... Why we need serilizable Interface in Employee class??
Hi I am getting a problem Using EJB 3.0 with JBoss5.1.

I got error


java.lang.reflect.UndeclaredThrowableException
at $Proxy2.addItem(Unknown Source)
at client.Test.main(Test.java:26)
Caused by: org.jboss.remoting.InvocationFailureException: Unable to perform invocation; nested exception is:
java.io.NotSerializableException: box.Employeer

If I am using String object instead of Employee object then code work fine. But using employee object giving me errors.

Please help me

Here is my code

Interface::

package box;
import java.util.List;

import javax.ejb.Remote;

@Remote
public interface NameRemote {
public void addItem(Employee emp);
public List<Employee> getItems();
}

Bean::


import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateful;
import javax.ejb.Stateless;

/**
* Session Bean implementation class Name
*/
@Stateful(mappedName = "helloBean")
public class NameBean implements NameRemote {

List<Employee> empList= new ArrayList<Employee>();
@Override
public void addItem(Employee emp) {
empList.add(emp);

}

@Override
public List<Employee> getItems() {

return empList;
}



}

Employee class:


package box;

public class Employee {
private String firstName;
private String lastName;
private String compName;
private double salary;

public Employee() {
firstName="Enter fn";
lastName="Enter ln";
compName= "Enter cn";
salary=0;
}
public Employee(String fn,String ln,String cn,double salary){
this.firstName=fn;
this.lastName=ln;
this.compName=cn;
this.salary=salary;

}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getCompName() {
return compName;
}
public void setCompName(String compName) {
this.compName = compName;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public String toString(){
return firstName+ " "+lastName+ " "+compName+ " "+ salary;
}

}

Main Class::

package client;

import java.util.Scanner;

import javax.naming.InitialContext;


import box.Employee;
import box.NameRemote;

public class Test {

private static Scanner scn= new Scanner(System.in);
public static void main(String[] args) {
String fn= scn.next();
String ln= scn.next();
String cn= scn.next();
double salary= Double.parseDouble(scn.next());
Employee emp= new Employee(fn, ln, cn, salary);


try {
InitialContext ctx= new InitialContext();
NameRemote obj= (NameRemote) ctx.lookup("helloBean");

obj.addItem(emp);

System.out.println(obj.getItems());

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}