Discussions

General J2EE: ClassCastException

  1. ClassCastException (4 messages)

    Hi all,

    there is a query like :

    List l = session.find(
    "select m.m1 , m.m2, ps.ps1 ,m.m3 from ex.M as m join m.propertyForSet as ps" +
    " where ps.ps2=3");
    System.out.println((A)l.get(0));

    and there is connection 1-to-n between N and M class

    A class contains m1,m2,m3,ps1 with their types but there is an error on line (A)l.get(0)



    Thanks for any help.

    Threaded Messages (4)

  2. ClassCastException[ Go to top ]

    Well... what type is A, why do you think the query contains an A, what does the query actually contain?
  3. ClassCastException[ Go to top ]

    hi,

    A class contains:
            private Long m1;
    private String m2;
    private int ps1 ;
    private float m3;
    M class contans:
    private Long m1= null;
    private String m2 = null;
    private float m3 = 0 ;
    private Set propertyForSet=new HashSet();

    N class contains:
    private Long nid = null ;
    private M mo= null ;
    private int ps1= 0 ;

    and I want to know how can I know the result fields and types when I don't access to it's class.

    Thanks for any help.
  4. Re: ClassCastException[ Go to top ]

    Try using more descriptive fields and class names!!!
    Maybe this is just an example but is doesn't supply usefull information. Speaking of which, the stackstrace should tell you excactly which class can't be casted to which class...
  5. ClassCastException[ Go to top ]

    hi,

    the real query is as below and there is connection 1-to-n between Product and Quantity and the result of both classes should be maintain in Khd class for iterate in jsp files next :

    List l = session.find("select p.product_id , p.name , p.price , pq.quantity from general.Product as p join p.pquantity as pq where pq.product_id=3");

    System.out.println(((Khd)(l.get(0))).getName());


    Quantity.java includes:

    private Long qid = null ;
    private Product product_id = null ;
    private int quantity = 0 ;
    and all set , get ...

    Quantity.hbm contains :
                  <many-to-one name="product_id" class="general.Product" column="product_id" />

    Product.java contains :
    private Long product_id = null;
    private String name = null;
    private float price = 0 ;
    private Set pquantity=new HashSet();
    and all set , get ...

    Product.hbm contains:
         <set name="pquantity" table="productQuantity" cascade="all" inverse="true" lazy="true">
             <key column="product_id"/>
       
             <one-to-many class="general.Quantity" />
             
          </set>

    error is on line System.out.println(((Khd)(l.get(0))).getName()); :
    java.lang.ClassCastException
    at general.UserService.getQuantityList(UserService.java:204)
    at org.apache.jsp.app_0005fdetails$jsp._jspService(app_0005fdetails$jsp.java:214)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
    ...
    and how can I know what the result is when type of class is not known?

    Thanks.