0

Object から取得したいのですが、この例外が発生しproposalInsuredPersonListました。を取得する方法を教えてください。lifeProposalproposal.ProposalInsuredPerson cannot be cast to java.util.ListList

            query.append("SELECT f.id, f.submittedDate, f.proposalNo, f.customer, f.organization, pi.proposedPremium, pi.proposedSumInsured, s.date, " +
                    "f.agent, f.proposalInsuredPersonList FROM LifeProposal f,LifeSurvey s INNER JOIN f.proposalInsuredPersonList pi where f.id = s.lifeProposal.id and f.id is not null");

            objectList = q.getResultList();
            for(Object[] b : objectList) {
                porposalId = (String) b[0];
                proposalDate = (Date) b[1];
                porposalNo = (String) b[2];
                if(b[4] == null) {
                    Customer c = (Customer) b [3];
                    customerName =  c.getFullName();
                    customerAddress =   c.getFullAddress();
                    fatherName = c.getFatherName();
                    phNo = c.getContentInfo() == null ? "" : c.getContentInfo().getPhone() ;
                } else {
                    Organization org = (Organization) b[4];
                    customerName = org.getName();
                    customerAddress = org.getFullAddress();
                    fatherName = null;
                    phNo = org.getContentInfo() == null ? "" : org.getContentInfo().getPhone() ;
                }
                inspectionDate = (Date) b[7];
                premium = (Double) b[5];
                sumInsured = (Double) b[6];
                if(b[8] == null) {
                    agentName = "";
                    agentNo = "";
                } else {
                    Agent a = (Agent) b[8];
                    agentName = a.getName();
                    agentNo = a.getCodeNo();
                }
                insuredPersonList = (List<ProposalInsuredPerson>)  b[9];
4

2 に答える 2

0

わかりました、ここに示したコードに基づいて、できる限りお答えします。結果セットをループし、返されたオブジェクトのインデックス 9 でオブジェクトを受け取りProposalInsuredPersonます。リスト全体が必要なため、このオブジェクトを for ループの外側で宣言およびインスタンス化されるList実装 (ArrayList頭に浮かぶ) に追加することをお勧めします。

そのようなものがあなたの問題を解決します:

リスト被保険者リスト = new ArrayList();

for () {
// your code here

// ...
  insuredPersonList.add((ProposalInsuredPerson) b[9]);
}
于 2013-09-11T10:59:26.700 に答える
0

次のようにクエリを書き直してみましたか:

query.append("SELECT f.id, f.submittedDate, f.proposalNo, f.customer, f.organization, pi.proposedPremium, pi.proposedSumInsured, s.date, " +
                    "f.agent, f FROM LifeProposal f,LifeSurvey s INNER JOIN f.proposalInsuredPersonList pi where f.id = s.lifeProposal.id and f.id is not null");

つまりf.proposalInsuredPersonList、全体に置き換えますf

そして最後の行でこれを行います:

insuredPersonList = ((LifeProposal) b[9]).getProposalInsuredPersonList();
于 2013-09-11T11:10:56.760 に答える