I have an EJB module with a remote interface, and an Enterprise Application Client (with a library that includes all the remote EJB's interfaces). Everything works fine when I call any business method from the remote EJB in the client, except when the EJB has to return me an Array of objects.
So transfering a String works fine, BUT IT WOULD NOT WORK WHEN i TRY TO SEND A AN ARRAY OF STRINGS.
Any ideas on this??? Do I need to create a Serializable object like this?? or WHAT?:
public class ArrayStrings () implements Serializable{
private String[] arrayS;
...
}
I don't know how can I pass an array in a remote ejb call. Any ideas?
Find bellow my code:
@Stateless
public class CategoryManagement extends AbstractFacade<Category> implements
CategoryManagementRemote {
@PersistenceContext(unitName = "On-lineSupermarketEJBPU")
private EntityManager em;
@Override
protected EntityManager getEntityManager() {
return em;
}
public CategoryManagement() {
super(Category.class);
}
@Override
public Category findCategoryByName (String name){
try{
Category c= (Category)em.createNamedQuery("Category.findByName").setParameter("name", name).getSingleResult();
for (Product p: c.getProductCollection()){
System.out.println(p.getName());
}
return c;
}catch(NullPointerException e){};
return null;
}
@Override
public List<String> getProductCollectionGivenCategory (String name){
Category c = findCategoryByName (name);
List<String> list=null;
for(Product p: c.getProductCollection()){
list.add(p.getName());
}
return list;
}
}
Then my remote interface (that is in a jar library in the classpath of the client):
@Remote
public interface CategoryManagementRemote {
Category findCategoryByName (String name);
List<String> getProductCollectionGivenCategory (String name);
}
And finally I call a method from the CategoryManagementRemote interface to just print out the array of Strings in the client:
public static void main(String[] args){
try{
InitialContext c = new InitialContext();
CategoryManagementRemote cm = (CategoryManagementRemote)
c.lookup("java:global/On-lineSupermarketEJB/CategoryManagement");
List<String> listProducts=
cm.getProductCollectionGivenCategory("Diary");
for (String p: listProducts){System.out.println(p);}
catch(Exception e){};
}
BTW I DONT GET ANY ERROR (I guess the try/catch catches the exception when trying to read the list of Strings). But the List is not printed out. (I am not receiving the list of Strings in the client (when just sending 1 single String it works)