[1.2.4] ClassCastException occured : [Ljava.lang.Object; cannot be cast to models.MyClass

1,287 views
Skip to first unread message

jss

unread,
Jan 22, 2012, 12:27:01 AM1/22/12
to play-framework
This is my query using entity manager. Trying to join 2 table with
play framework and jpa.

List<Object> joinQryResult = JPA.em().createNativeQuery(
"select e.elementname as elementname, " +
"c.comparetype as comparetype, " +
"jd.matchvalue as matchvalue " +
"from details jd " +
"join elements e on jd.elementnamerid = e.rid " +
"join comparers c on jd.comparetyperid = c.rid " +
"where jd.rid = " + temp.rid).getResultList();

Not sure how to iterate and get the values from List<Object>

I tried this

List<MyClass> myClass = (List<MyClass>)(Object)joinQryResult;


for(MyClass myC:jd)
{
System.out.println(myC.ElementName); //intellisense shows the
property here
}


MyClass definition: ttrying to convert List<object> to this type

public class MyClass {

public String ElementName;

public String CompareType;

public String MatchValue;

public JobDetails(String ElementName, String CompareType,
String MatchValue)
{
this.ElementName = ElementName;

this.CompareType = CompareType;

this.MatchValue = MatchValue;
}
}

Get this error

ClassCastException occured : [Ljava.lang.Object; cannot be cast to
models.MyClass


ARAKI Hayato

unread,
Jan 22, 2012, 10:09:57 AM1/22/12
to play-fr...@googlegroups.com
I think you could do something like

List<MyClass> joinQryResult = JPA.em().createNativeQuery(sql, MyClass.class);

Reply all
Reply to author
Forward
0 new messages