views:

79

answers:

1

I'm trying to do the following:

public String createByMarcas() {
    items = (DataModel) ejbFacade.findByMarcas(current.getIdMarca().getId());
    updateCurrentItem();
    return "List";
}

public List<Modelos> findByMarcas(int idMarca){
    return em.createQuery("SELECT id, descripcion FROM Modelos WHERE id_marca ="+idMarca+"").getResultList();
}

But I keep getting this expection:

Caused by: javax.ejb.EJBException
 at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5070)
 at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:4968)
 at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4756)
 at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955)
 at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1906)
 at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198)
 at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84)
 at $Proxy347.findByMarcas(Unknown Source)
 at controladores.__EJB31_Generated__ModelosFacade__Intf____Bean__.findByMarcas(Unknown Source)

Can anyone give a hand please? Thank you very much

+1  A: 

I guess the most obvious answer to your question is no. You query retuns a java.util.List, which is unrelated to a JSF DataModel, assuming that that's what you're casting to. I know nothing about JSF, but it seems that there is a ListDataModel which can be used to wrap a List, so that might help in your case.

Arjan Blokzijl
Yes I'm casting to a JSF DataModel, I will try the ListDataModel but do you know anything about this exception? em is EntityManager, if it helps shouldn't it work?
Ignacio
I don't know your setup, but from what I know about JPA, the EJBException is thrown when a method cannot be completed normally due to an exception. In your case it should wrap a ClassCastException, I would expect. Is the stacktrace you supplied complete?
Arjan Blokzijl
no Is not complete it actaully quite big, should I paste it here?
Ignacio
You need `new ListDataModel(ejbFacade.findByMarcas(current.getIdMarca().getId()));`.
BalusC
Thanks Balus but still throws same excecption
Ignacio
The stacktrace is completely unrelated to the question "Can List be casted to DataModel?". This exception is already thrown long before the attempt to cast has been taken place. Reframe your question. It's an EJB problem, not a casting problem.
BalusC