• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.reflect.UndeclaredThrowableException

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}

}

}

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic