java.lang.Object 상위; 모델 클래스에 캐스트 할 수 없습니다 오류를 봄 부팅에

야곱 :

나는 봄 부트를 사용하여 JPQL 쿼리를 사용하여 데이터베이스의 데이터를 가져 오는 루프에 데이터를하려 할 때, 나는 다음과 같은 오류를 얻고있다

{
"message": "[Ljava.lang.Object; cannot be cast to com.spacestudy.model.RoomCPCMapping",
"error": "Internal Server Error",
"path": "/spacestudy/rockefeller/survey/surveyform/occupant/getClientCPCWithPercentage"
}

다음과 같은 내 저장소 쿼리

@Query("SELECT u.nCCPCode,u.nPercent FROM RoomCPCMapping u JOIN u.clientCPC ur where u.nRoomAllocationId=:nRoomAllocationId")
List<RoomCPCMapping> findNCCPCodeByNRoomAllocationID(@Param(value="nRoomAllocationId") Integer nRoomAllocationId );

그리고, 다음과 같은 쿼리 함수를 호출하고

List<RoomCPCMapping> 
        roomCpcMappingCodeObj = roomCPCMappingRepositoryObj.findNCCPCodeByNRoomAllocationID(nRoomAllocationID);

결과 개체를 사용하여, 나는 다음과 같은 루프를 시도하고있다

for(RoomCPCMapping rpcLoopObj:roomCpcMappingCodeObj)
    {
        if(clientCpcCodeMappingLoopObj.nClientCPCMappingId==rpcLoopObj.getnCCPCode())                    
             {
                clientCpcCodeMappingLoopObj.nPercentage=rpcLoopObj.nPercent;
                }
    }

클래스는 다음과 같은 내 모델,

@Entity
@Table(name="roomccpcmapping")
public class RoomCPCMapping implements Serializable
{   

/**
 * 
 */
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "roomccpcmapping_seq_generator")
@SequenceGenerator(name = "roomccpcmapping_seq_generator", sequenceName = "roomccpcmapping_seq",allocationSize=1)

@Column(name="nroom_ccpc_mapping_id", columnDefinition="serial")
public Integer nRoomCcpcMappingId;

@Column(name="nroom_allocation_id")
public Integer nRoomAllocationId;

@Column(name="nccp_code")
public Integer nCCPCode;

@Column(name="npercent")
public Integer nPercent;

@Column(name="nresponsible_person_id")
public Integer nResponsiblePersonId;

@ManyToOne(optional = true, cascade = { CascadeType.MERGE })
@JoinColumn(name = "nccp_code", insertable = false, updatable = false)
public ClientCostPoolCodes clientCPC ;

public Integer getnRoomCcpcMappingId()
{
    return nRoomCcpcMappingId;
}

public void setnRoomCcpcMappingId(Integer nRoomCcpcMappingId) 
{
    this.nRoomCcpcMappingId = nRoomCcpcMappingId;
}

public Integer getnRoomAllocationId()
{
    return nRoomAllocationId;
}

public void setnRoomAllocationId(Integer nRoomAllocationId)
{
    this.nRoomAllocationId = nRoomAllocationId;
}

public Integer getnCCPCode() 
{
    return nCCPCode;
}

public void setnCCPCode(Integer nCCPCode) 
{
    this.nCCPCode = nCCPCode;
}

public Integer getnPercent()
{
    return nPercent;
}

public void setnPercent(Integer nPercent)
{
    this.nPercent = nPercent;
}

public Integer getnResponsiblePersonId() 
{
    return nResponsiblePersonId;
}

public void setnResponsiblePersonId(Integer nResponsiblePersonId)
{
    this.nResponsiblePersonId = nResponsiblePersonId;
}

public ClientCostPoolCodes getClientCPC() 
{
    return clientCPC;
}

public void setClientCPC(ClientCostPoolCodes clientCPC)
{
    this.clientCPC = clientCPC;
}


public RoomCPCMapping(Integer nRoomCcpcMappingId, Integer nRoomAllocationId, Integer nCCPCode, Integer nPercent,
        Integer nResponsiblePersonId, ClientCostPoolCodes clientCPC) {
    super();
    this.nRoomCcpcMappingId = nRoomCcpcMappingId;
    this.nRoomAllocationId = nRoomAllocationId;
    this.nCCPCode = nCCPCode;
    this.nPercent = nPercent;
    this.nResponsiblePersonId = nResponsiblePersonId;
    this.clientCPC = clientCPC;
}

public RoomCPCMapping() {

 }
}

왜 오류가 이러한 종류는 무엇입니까?

마치에이 코왈 스키 :

옵션 1) 있는지 확인은 RoomCPCMapping투사 인터페이스입니다 :

public interface RoomCPCMappingResult {

    String getNCCPCode();
    String getNPercent();

    ...
}

옵션 2) 결과 클래스 레거시 옵션을 사용합니다 :

SELECT new com.my.package.RoomCPCMappingResult(u.nCCPCode,u.nPercent)
FROM RoomCPCMapping u JOIN u.clientCPC ur 
where u.nRoomAllocationId=:nRoomAllocationId

단지 당신이 거기에 적절한 생성자의 존재를 확인하십시오.

추천

출처http://43.154.161.224:23101/article/api/json?id=20121&siteId=1