wood burning stoves*
The moose likes EJB and other Java EE Technologies and the fly likes java.lang.reflect.UndeclaredThrowableException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "java.lang.reflect.UndeclaredThrowableException" Watch "java.lang.reflect.UndeclaredThrowableException" New topic
Author

java.lang.reflect.UndeclaredThrowableException

ramand singh
Greenhorn

Joined: Jul 05, 2011
Posts: 2
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

Joined: Apr 27, 2008
Posts: 342
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!


SCJP 5 (98%) - SCBCD 5 (98%)
ramand singh
Greenhorn

Joined: Jul 05, 2011
Posts: 2
Thanks

It works... Why we need serilizable Interface in Employee class??
Ralph Jaus
Ranch Hand

Joined: Apr 27, 2008
Posts: 342
Why we need serilizable Interface in Employee class??

The underlying rmi protocoll requires that all objects that are invoked remotely have to be serializable.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.reflect.UndeclaredThrowableException