需要解决org.springframework.core.convert.ConversionFailedException

时间:2019-04-25 16:36:42

标签: java spring-boot jpa

  1. 当尝试获取Organisationinfo详细信息时,我的意思是“例外”:
"org.springframework.core.convert.ConversionFailedException",
"message": "Failed to convert from type [java.lang.Object[]] to type [com.cisco.resourceApp.models.Organisationinfo] for value '{3, fdsfddghjhgf}'; 
nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Long] to type [com.cisco.resourceApp.models.Organisationinfo]"
  1. 下面是实体类
@Entity
public class TeamsInfo {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    @Column(unique = true)
    private String username;
    private String password;
    private String pool;
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name="orgId")
    private Organisationinfo orginfo;
    private int createdBy;
    @Column(updatable=false)
    @CreationTimestamp
    private Date createdTime;
    private int updatedBy;
    @UpdateTimestamp
    private Date updatedTime;
  1. 道:
    @Repository
    public interface TeamsInfoRepo extends JpaRepository<TeamsInfo, Long>{

        //@Query("select o.id, o.orgId from Organisationinfo o where o.orgId=:orgId",Organisationinfo.class )
        @Query("select o.orginfo.id, o.orginfo.orgId from TeamsInfo as o where o.orginfo.orgId=:orgId")
        Organisationinfo checkAlreadyExist(@Param("orgId") String orgId);
  1. 服务类别:
 private TeamsInfoRepo teamsRepo;
        @Override
        public TeamsInfo save(TeamsInfo teamsInfo) {
            // TODO Auto-generated method stub
            Organisationinfo OrgInfo=teamsRepo.checkAlreadyExist(teamsInfo.getOrginfo().getOrgId().toString());
            if(OrgInfo.getOrgId()!=null)
            {

                teamsInfo.getOrginfo().setId((long)teamsRepo.checkAlreadyExist(teamsInfo.getOrginfo().getOrgId().toString()).get(0).getOrginfo().getId());

            }
            return teamsRepo.save(teamsInfo);
        }

0 个答案:

没有答案