• 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

ava.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 2 tables
Pojo class
Deviceanalogfeaturess.java



Fuelrecord.java



main files


I got the following error
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your query is selecting both classes ... you are actually getting back an array with [0] containing Deviceanalogfeaturess and [1] containing the Fuelrecord.

The correct code would be something along the lines of :

 
Baktha Elumalai
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

thanks for your reply

i change something regarding your reply

like this



but the valur printed both as same
ObjectId 18
Minvalue 18

but in our case Minvalue from fuelrecord is 10 but it will print only 18
hoe to solve this one

please help me
 
Baktha Elumalai
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry this is my mistake

i changed

Iterator query = session.createSQLQuery("select {d.*}, {f.*} from deviceanalogfeaturess d join fuelrecord f on d.objectId=f.objectId where d.objectId= '" + ObjectId + "'").addEntity("d", Deviceanalogfeaturess.class).addEntity("f", Fuelrecord.class).list().iterator();
// rs3 = st.executeQuery("select navl.deviceanalogfeatures.ObjectId,navl.fuelrecord.MinValue from navl.deviceanalogfeatures inner join navl.fuelrecord on navl.deviceanalogfeatures.ObjectId = navl.fuelrecord.ObjectId where navl.deviceanalogfeatures.ObjectId='" + ObjectId + "'");
while (query.hasNext())
{
Object[] row = (Object[]) query.next();
Deviceanalogfeaturess d =(Deviceanalogfeaturess) row[0];
analog = d.getObjectId();
Fuelrecord f =(Fuelrecord)row[1];
cdiff = f.getMinValue();
}

System.out.println("ObjectId" +analog);
System.out.println("Minvalue" +cdiff);

System.out.println("Minvalue" +analog); changed to System.out.println("Minvalue" +cdiff);

Now it's work fine

thanks for your reply
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, in the future please make sure to add linebreaks to code you post - not everyone has 3 feet wide screens.
 
Baktha Elumalai
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for my mistake

In future defiantly i add line breaks
 
reply
    Bookmark Topic Watch Topic
  • New Topic