0

我想proposalInsuredPersonListlifeProposalObject 中检索。但我得到了这个异常proposal.ProposalInsuredPerson cannot be cast to java.util.List。让我知道如何检索List

            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 回答