ClassCastException: java.util.Vector

I'm trying to get a list of records(products) from the dataBase and print them into a jsp page.
Here is the code-
Method in session bean to get the records-
public List<Entity.Products> getProducts(int categoryId)
      Query query=manager.createNativeQuery("select * from products  where categoryId="+categoryId);
      return (List<Entity.Products>)query.getResultList();
    }I put the result in the request (in a servlet)-
   request.setAttribute("products",productsManagement.getProducts(categoryId));JSP page-
      <%
         java.util.List<Entity.Products> products=(java.util.List<Entity.Products>) request.getAttribute("products");
          for(Entity.Products product : products)
           %>
        <A href=""><%=product.getProductName()%></A>
           <%
           %>The problen is that i'm getting the error-
java.lang.ClassCastException: java.util.Vector
what is the problem?
Thanks in advanced.

ppl1,
Your problem is with createNativeQuery. Native query returns a Vector of objects. Whereas createNamedQuery (based on JPQL) is smart enough to get the types right. It seems like you want to use createNamedQuery which will allow you to use generics with the Entity type.
For example, with a client
List<Products> products = prodMgr.findAllProducts();
for(Product p : products) {
System.out.println(p");
}The following session bean will work.
// ProdManager
@PersistenceContext EntityManager em;
public List<Product> findAllProducts() {
  // JPQL for findAllDepts: SELECT p FROM Product AS p
  return em.createNamedQuery("findAllDepts");
}If you are committed to native query, use the following on the client and EJB respectively.
List products = prodMgr.findAllProducts();
for( Object obj : products ) {
  System.out.println( obj.toString());
  // use a case "(Product)obj" for field-level access
List findAllProducts() {
return em.createNativeQuery("SELECT * FROM products").getResultList();
}

Similar Messages

  • Throw "java.util.Vector" exception?

    In my servlet, I got catch(Throwable t), t.getMessage() is java.util.Vector. Can anyone tell me where I should look into for this problem?

    probably a ClassCastException. Why don't you get the stack trace?

  • Help needed to solve "java.io.NotSerializableException: java.util.Vector$1"

    hi to all,
    i am using a session less bean A to querry a Entity Bean B , which inturns calls another EntityBean C ,
    finally a ' find' method is invoked on the EntityBean C, In this a vector is created which holds 3 different vectors at different indexes, now the problem i am facing is that when Enity Bean B is returning the final vector to the A , it's firing out a errors that :-
    TRANSACTION COULD NOT BE COMPLETED: RemoteException occurred in server thread;
    ested exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.rmi.ServerException: RemoteException occurred in server thread; ne
    ted exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.rmi.ServerException: RemoteException occurred in server thread; nested exc
    ption is:
    java.rmi.RemoteException: null; nested exception is:
    java.rmi.ServerException: RemoteException occurred in server thread; ne
    ted exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.rmi.RemoteException: null; nested exception is:
    java.rmi.ServerException: RemoteException occurred in server thread; ne
    ted exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.rmi.ServerException: RemoteException occurred in server thread; nested exc
    ption is:
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.io.NotSerializableException: java.util.Vector$1
    <<no stack trace available>>
    ur any help would be highly appricated to solve out this prob.
    If i try to iterate through this vector it's gives IOR:0232003x343242344asdsd................................................blabla....................
    thanxs in adavance
    Deepak

    Hi I think you are using the method elements() in a remote method.
    This method can't be Serializable!! Because it returns an Interface. Interfaces are never Serializable.
    Regards,
    Peter

  • Problems with protected access in java.util.vector

    Hi,
    basically i'm trying to use the method removeRange(int,int) of class Vector from the java API.
    I keep getting the following compiler message:
    removeRange(int,int) has protected access in java.util.vector.
    This seems rather vague, and i don't know quite what to do?
    Thanks in advance

    removeRange(int,int) has protected access in java.util.vector.
    This seems rather vague, and i don't know quite what to do?As error messages go, that's pretty clear: method removeRange is a protected method and you can only call public ones of Vector, right? You can always combine subList and clear:
    vec.subList(fromIndex, toIndex).claer();

  • Service component:  java.lang.NoSuchMethodException: java.util.Vector.isX()

    Hi everybody:
    I created a Mobile service component and a Data Structure with 3 attributes. I created and instantiated the collection and showed all objects in a table but I´m getting the following error:java.lang.NoSuchMethodException: java.util.Vector.isX() where X is the name of the each attribute I defined. so I´m getting this error twice for each attribute.
    Complete stack:
    java.lang.NoSuchMethodException: java.util.Vector.isX()
         at java.lang.Class.getMethod(Class.java:1581)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.JavaBeanCMIModel.invokeMethod(JavaBeanCMIModel.java:366)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.JavaBeanCMIModel.invokeGetMethod(JavaBeanCMIModel.java:279)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.JavaBeanCMIModel.getAttributeValue(JavaBeanCMIModel.java:81)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.NodeElement.getAttributeValue(NodeElement.java:104)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.NodeElement.getAttributeValue(NodeElement.java:85)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.NodeElementWrapper.getAttributeValue(NodeElementWrapper.java:26)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.ContextNode.getAttributeValue(ContextNode.java:578)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.ContextNode.getAttributeValue(ContextNode.java:569)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.ContextNodeMapped.getAttributeValue(ContextNodeMapped.java:134)
         at com.sap.tc.mobile.wdlite.progmodel.core.viewelement.Property.listenContextNodeCursorChanged(Property.java:173)
         at com.sap.tc.mobile.wdlite.progmodel.core.context.ContextNode.addContextNodeElementListener(ContextNode.java:616)
         at com.sap.tc.mobile.wdlite.progmodel.core.viewelement.Property.setBinding(Property.java:73)
         at com.sap.tc.mobile.wdlite.progmodel.core.viewelement.Property.setBinding(Property.java:57)
         at com.xioma.demo.testeui0001.comp1.Comp1ViewView.(Comp1ViewView.java:615)
         at com.xioma.demo.testeui0001.comp1.Comp1ViewView.getInstance0(Comp1ViewView.java:31)
         at com.xioma.demo.testeui0001.comp1.Comp1ViewView.getInstance(Comp1ViewView.java:45)
         at com.xioma.demo.testeui0001.comp1.Comp1WindowWindow.getDefaultView(Comp1WindowWindow.java:38)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.navigate(Application.java:477)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.enter(Application.java:243)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.setCurrent(Application.java:119)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.launch(Application.java:143)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.launch(Application.java:175)
         at com.sap.tc.mobile.wdlite.progmodel.core.WDLite.launchApplication(WDLite.java:387)
         at com.sap.tc.mobile.wdlite.container.ContainerApp.startApp(ContainerApp.java:155)
         at com.sap.tc.mobile.wdlite.container.AppMenuView.onActionLaunchApp(AppMenuView.java:327)
         at com.sap.tc.mobile.wdlite.container.AppMenuView.invokeEventHandler(AppMenuView.java:370)
         at com.sap.tc.mobile.wdlite.progmodel.core.AbstractViewElement.doHandleEvent(AbstractViewElement.java:207)
         at com.sap.tc.mobile.wdlite.renderer.api.UIElement.doHandleEvent(UIElement.java:399)
         at com.sap.tc.mobile.wdlite.renderer.api.UIImageButton.mouseReleased(UIImageButton.java:148)
         at com.sap.tc.mobile.wdlite.renderer.api.UIElement.dispatchMouseReleasedWidgetEvent(UIElement.java:442)
         at com.sap.tc.mobile.wdlite.renderer.api.UIElement$1.mouseReleased(UIElement.java:485)
         at com.sap.tc.mobile.wdlite.renderer.swt.MouseEventDispatcher.mouseUp(SWTControl.java:362)
         at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:137)
         at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
         at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
         at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
         at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
         at com.sap.tc.mobile.wdlite.renderer.swt.container.WorkingArea.refresh(WorkingArea.java:175)
         at com.sap.tc.mobile.wdlite.renderer.api.RenderingManager.refresh(RenderingManager.java:233)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.refresh(Application.java:250)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.navigate(Application.java:503)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.enter(Application.java:243)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.setCurrent(Application.java:119)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.launch(Application.java:143)
         at com.sap.tc.mobile.wdlite.progmodel.core.Application.launch(Application.java:175)
         at com.sap.tc.mobile.wdlite.progmodel.core.WDLite.launchApplication(WDLite.java:387)
         at com.sap.tc.mobile.wdlite.framework.Start.runOnContext(Start.java:585)
         at com.sap.tc.mobile.wdlite.framework.Start.startApplication(Start.java:609)
         at com.sap.tc.mobile.wdlite.framework.Start.startContainer(Start.java:646)
         at com.sap.tc.mobile.cfs.framework.spi.FrameworkManager.startContainer(FrameworkManager.java:259)
         at com.sap.tc.mobile.cfs.init.FrameworkInitializer.init(FrameworkInitializer.java:230)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.sap.tc.mobile.cfs.startup.pda.Startup.main(Unknown Source)
    The errors are throw when the application starts, the custom code works ok.
    Any idea?
    Thanks a lot for your time on this thread.
    Rocío.

    Ho Rocio,
    The creme JVM is compatible with JDK 1.3.Please make sure that the API you are using is available in 1.3 API set.
    Best Regards,
    Amit

  • Error processing WSDL document: java.lang.ClassCastException: java.util.Ar

    Hi
    Program is giving unpredictable behaviour.
    Am trying to consume webservice using Axis Client.
    When running as stand alone Java programs its working fine.
    But when deployed on OC4J its giving problem
    Error processing WSDL document: java.lang.ClassCastException: java.util.ArrayList
    Could you please give some hint
    Regards
    Bajarang

    Here is the program
    QName serviceQN = new QName(targetNamespace,serviceName );
    System.out.println("After serviceQN "+ serviceQN);
    QName portQN = new QName( targetNamespace, portName );
    System.out.println("After port "+ portQN);
    // This Call object will be used the invocation
    Service service = new Service(implURI,serviceQN);
    System.out.println("After service "+ service);
    Call call = (Call) service.createCall();
    System.out.println("After call "+ call);
    // Now make the call...
    System.out.println("Invoking service>> " + serviceName + " <<...");
    call.setOperation(portQN,operationName);
    call.invoke( inputParams );
    System.out.println("Result returned from call to "+ serviceName+" ");
    Error while execution
    javax.xml.rpc.ServiceException: Error processing WSDL document:
    java.lang.ClassCastException: java.util.ArrayList

  • Java.io.NotSerializableException: java.util.Vector$1

    I am using Java 2 in the API it says that the Vector implements Serializable but I am getting an exception java.io.NotSerializableException: java.util.Vector$1 I don't know why please help.
    Thank you
    palanisr

    Although Vectors are Serializable that doesn't mean that the contents of a Vector are necessarily Serializable. What are the contents of your Vector? Are they objects of a Serializable class? If not that is your problem. The attached sample code demonstrates the problem of serializing a Vector that contains non-serializable data. If you make the Employee class Serializable the code works.
    import java.util.*;
    import java.io.*;
    public class Serialize
    public static void main(String args[])
      ObjectOutputStream oos = null;
      FileOutputStream fos = null;
      Vector v = new Vector();
      v.add(new Employee("Smith","John"));
      v.add(new Employee("Jones","Albert"));
      try
       fos = new FileOutputStream("vector.ser");
       oos = new ObjectOutputStream(fos);
       oos.writeObject(v);
      catch(FileNotFoundException fnfe)
       fnfe.printStackTrace();
      catch(IOException ioe)
       ioe.printStackTrace();
      finally
       try
        if (oos != null)
         oos.close();
       catch(IOException ioe)
       try
        if (fos != null)
         fos.close();
       catch(IOException ioe)
    class Employee //implements Serializable
    private String lastName;
    private String firstName;
    public Employee(String lastName, String firstName)
      this.lastName = lastName;
      this.firstName = firstName;
    }

  • Java.lang.NoSuchMethodError: java/util/Vector method revove...

    After using jexegen from microsoft to make EXE. I receive this error when i execute the my EXE :
    java.lang.NoSuchMethodError: java/util/Vector method revove...
    Any body know why?
    If i execute from JBuilder i have no problem!

    hi, i don't have much experience with M$ java products, but as far as i remember, M$ java stopped developping since jdk 1.1.4 (or 1.1.7).
    maybe that's the reason for throwing this exception. if you want to "exe" your class-file, try JToExe.
    greetzzz
    chris

  • Any benefit to import java.util.Vector over import java.util.*?

    By benefit I mean does it reduce compile time or have some other beneficial side effect to import only those classes you're using in a class rather than importing the package they reside in.
    For example:
    // this?
    import java.util.Vector;
    // or this..
    import java.util.*;
    class Test
         Vector v;
    }Question is strictly academic...I'm just curious.

    I like Dr. clap's answer. Also, though you can
    consider code readability. Obviously importing a
    whole package doesn't give you an idea of what classes
    are being used. "I", personally, have only seen exact
    class imports done when learning something new. This
    is basically just for clarity, and not speed as Dr.
    Clap pointed out.That's probably a good thing to do for examples, but I can't see why you would want to know what individual classes are being used otherwise.
    From a programming standpoint if you're going to build a complex dialog you don't want 500 import statements. If you know you're going to be using lots of classes from an individual package might as well import the whole thing.

  • Java.util.vector package

    What is in the java.util.vector package and why is it used (imported)?
    Thanks

    Can you tell me what the Vector class is use for?First of all, forget about Vector. When anyone mentions Vector, your response should be "You're still using Vector? Are you still in 1.1?"
    Use ArrayList. It's basically the same but better. It's a List. You know what a List is right? It's a group or ordered items that can contain duplicates. An ArrayList is basically a List that is backed by an array. The greate thing about it is that it automatically makes itself bigger as needed and implements probably the most commonly supported Java type: Collection.

  • Java.util.Vector

    Hello,
    I keep getting this error message, although things used to work fine before.
    Error : Method toArray(SecurityConstraint[]) not found in class java.util.Vector.
    PolicyEnforcer.java line 36
    Snippet of code
    import java.util.*;
    //blabla
    Vector constraints = inv.getConstraints();
    SecurityConstraint [] constr = (SecurityConstraint [])constraints.toArray(new SecurityConstraint[0]);Any ideas what could be wrong??
    thanx

    Hi,
    Why not try this:
      SecurityConstraint[] constr = (SecurityConstraint[])                                       
        constraints.toArray( new SecurityConstraint[constraints.size()] );HTH
    ~Bill

  • Java.util.vector value to String

    Hi
    I am trying to use some API calls for securecomputing. One of the value when i print using API, i get the result as
    java.util.Vector$1@93d6bc
    How do i convert this value into readable string format.
    Thanks for any help
    Joseph

    Even after adding toString() it still returns the
    same value.
    System.out.println("Role " +
    (user.getValue(User.IDS_ROLE)).toString());
    Returns "Role java.util.Vector$1@93d6bc"
    User.IDS_ROLE is an int
    Thanks for the repliesWe didn't mean for you to explicitly call toString(), we meant for you to implement it. What kind of class does user.getValue(int) return? Surely it's not a java.util.Vector, but something else - what it is returning looks confusing (java.util.Vector$1...)

  • HELP?! a class that implements .....  : java.util.Vector

    My instructions say this:
    In the constructor, create the collection object (Since java.util.List is an interface, you will need to instantiate a class that implements this interface: java.util.Vector or java.util.LinkedList or java.util.ArrayList).
    I know, this IS a homework assignment - I am not sure how to go about this. I DO have code so far up to this point, can anyone help?
    import dLibrary.*;
    import java.awt.Color;
    * @author Rob
    * @version 8/18/03
    public class PhrasesII extends A3ButtonHandler
            private A3ButtonWindow win;
            private ATextField stringAcceptor;
            private ALabel listOstrings;
            private ALabel inputString;
            private ALabel status;
            private java.awt.List display;
            private java.util.List collection;
    public PhrasesII()
            win = new A3ButtonWindow(this);
            stringAcceptor= new ATextField (50,420,200,25);
            stringAcceptor.place(win);
            listOstrings = new ALabel(100, 10, 100, 380);
            listOstrings.setFontSize(10);
            listOstrings.setText("List of Strings:");
            listOstrings.place(win);
            inputString = new ALabel(50,400,200,25);
            inputString.setFontSize(10);
            inputString.setText("Input String:");
            inputString.place(win);
            display = new java.awt.List();
            display.setLocation(200, 100);
            display.setSize(200, 250);
            display.setBackground(Color.lightGray);
            win.add(display, 0);
            win.setLeftText("Save");
            win.setMidText("Display");
            win.setRightText("Discard");
            win.repaint();
      public void leftAction()
        public void midAction()
        public void rightAction()

    I am getting a " can't resolve symbol" when I do thisYou have to either import java.util.ArrayList or specify it fully, e.g., "new java.util.ArrayList()".
    Is that the line that is causing you problems? The error message should give the line number.
    my instructions also say I have to use "interface
    java.util.List when declaring your reference" so I am
    confused about using "= new ArrayList();"What they're saying is that you want code like this:
    private java.util.List frogs;    // this is the reference declaration
    //... later on...
    frogs = new java.util.ArrayList();  // this isn't a declarationWhat this means is that when you declare a field or variable, you should declare its type to be an interface.
    But when you actually instantiate a value for that variable, then you should use a concrete class that implements that interface. (You have to; interfaces can't be instantiated.)
    This is good programming style for reasons I don't have the space to explain here.

  • Error: java.lang.ClassCastException: java.util.Arrays$ArrayList

    Hi,
    How to solve this error?
    I get the error at this line of code in my program.
    java.util.ArrayList list= (java.util.ArrayList)obj;
    Please help how to solve this problem.
    Thanks,
    cmbl

    cmbl wrote:
    How to solve this error?
    I get the error at this line of code in my program.
    java.util.ArrayList list= (java.util.ArrayList)obj; Don't do this cast.
    Why are you doing this cast anyway? I think you need to show a small bit of compilable code (or almost compilable except perhaps for this error) and some more explanation.

  • Type Mapping Problem with java.util.Vector in Axis

    Hi,buddies,I want to use the Vector class as the return type of my service, but it seems that there isn't a built-in Ser/Deser factory for Vector, is it?So i think we need to provide our own Ser/Derser. and this is a very common problem,and i wonder how to write my own Ser/Derser, please give me some suggestion,thx!
    Best Regards:)

    Hi,I checked out the src of Axis 1.2, I found there is a org.apache.axis.encoding.ser.VectorSerializerFactory class and an according org.apache.axis.encoding.ser.VectorDeserializerFactory class.so in the deploy.wsdd i use them as the ser/deser factories in the TypeMapping part inside the service tag.everything goes well and i got no problem deploying the service to axis.But the problem is that when i try to invoke the service and get a vector as return(Suppose the components in the vector is instances of Movie class), the following error occured:
    org.xml.sax.SAXException: No deserializer for {urn:movies}Movie
    But it is a little bit confusing,for I declared the ser/deser factories for the bean class Movie(with built-in ser/deser factories of axis),and everything was going fine when i deployed the service to axis.So should i still use the TypeMappingRegistry or there are something i just missed.Please give me some suggestion,thx :)
    Best Regards:)

Maybe you are looking for