0
這是我的查詢使用實體管理器。試圖加入2表與玩框架和jpa。迭代列表<Object>來自加入查詢使用JPA/PLay
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>
我想這
List<MyClass> myClass = (List<MyClass>)(Object)joinQryResult;
for(MyClass myC:jd)
{
System.out.println(myC.ElementName); //intellisense shows the property here
}
MyClass的定義:ttrying到列表轉換爲這種類型的
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;
}
}
得到這個錯誤
ClassCastException occured : [Ljava.lang.Object; cannot be cast to models.MyClass