• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Baktha Elumalai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 tables
Pojo class
Deviceanalogfeaturess.java



Fuelrecord.java



main files


I got the following error
 
Craig Taylor
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • 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: 34
  • Mark post as helpful
  • send pies
  • 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: 34
  • Mark post as helpful
  • send pies
  • 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
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • 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: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for my mistake

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