This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.reflect.UndeclaredThrowableException

 
ramand singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}

}

}

 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if the Employee class implements the Serializable interface ?

What makes me wonder, too, is the error message part "box.Employeer ": Nowhere in your code the word "Employeer" occurs!
 
ramand singh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

It works... Why we need serilizable Interface in Employee class??
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why we need serilizable Interface in Employee class??

The underlying rmi protocoll requires that all objects that are invoked remotely have to be serializable.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic