为什么为什么我的Class不能为null异常?

时间:2018-08-28 04:41:32

标签: java hibernate jpa

我正在尝试更新名为PartnerPIDInfo的表中的列, 用下面的代码:

private HashMap<String, String> insertPartnerPIDInfoEntries(String 
partnerId, String environment, List<PartnerPidEntity> partnerPidInfoEntries, 
String user) {
    HashMap<String, String> resultMap = new HashMap<>();

    for (PartnerPidEntity partnerPidInfoEntry : partnerPidInfoEntries) {
        logger.info("PartnerPidEntity entry:{}", partnerPidInfoEntry);
        //String key = partnerPidInfoEntry.getPartnerId() +"|"+ 
       partnerPidInfoEntry.getPID();
        partnerPidInfoEntry.setPartnerId(partnerId);
        String key = partnerPidInfoEntry.getPartnerId()+"|"+ 
        partnerPidInfoEntry.getBannerOMSPid();
        logger.info("PartnerPidEntity Key:" + key);
        try {
            partnerPidInfoEntry.fillDefaultField();
            omsdbReadWriteWrapper.insertPartnerPidInfoEntry(environment, 
            partnerPidInfoEntry);
            resultMap.put(key,"Success");
        } catch (Exception e) {
            logger.error("Exception writing into PartnerPidEntity:" + 
             e.getMessage());
            resultMap.put(key,"Failed");
        }
    }
    return resultMap;
}
  • PartnerPidEntity类:

     @Entity
     @Table(name = "dbo.PartnerPIDInfo", schema = "", catalog = "Coupons")
     public class PartnerPidEntity implements Serializable{
     private static final long serialVersionUID = 1L;
    
    
     private String partnerId;
     private Integer bannerPid;
     private Timestamp createDate;
     private Boolean isActive;
    
    @Id
     @Column(name = "PartnerId", nullable = false, length = 64)
     public String getPartnerId() {
     return partnerId;
      }
    
     public void setPartnerId(String partnerId) {
     partnerId = partnerId;
     }
    
    @Id
     @Column(name = "PID", nullable = false, length = 20)
     public Integer getBannerOMSPid() {
     return bannerPid;
      }
    
     public void setBannerOMSPid(Integer bannerPid) {
     this.bannerPid = bannerPid;
     }
    
     @Basic
     @Column(name = "CreateDate", nullable = false, length = 20)
     public java.sql.Timestamp getCreateDate() {
     return createDate;
     }
    
     public void setCreateDate(java.sql.Timestamp createDate) {
      this.createDate = createDate;
      }
    
    @Basic
    @Column(name = "IsActive", nullable = false,  length = 10)
     public Boolean getIsActive() {
    return isActive;
    }
    
     public void setIsActive(Boolean isActive) {
       this.isActive = isActive;
      }
     public PartnerPidEntity fillDefaultField(){
    this.createDate = new java.sql.Timestamp(System.currentTimeMillis());
    return this;
    }
    }
    

在一行partnerPidInfoRepo.save(partnerPIDInfoEntity); 我最终得到的类不能为null异常。 还添加了PartnerPidInfo表的架构:

TABLE "PartnerPIDInfo" (
"PartnerId" VARCHAR(64) NOT NULL,
"PID" INT NOT NULL,
"CreateDate" DATETIME NOT NULL,
"IsActive" BIT NOT NULL,
PRIMARY KEY ("PartnerId", "PID")
)

异常日志:

 PartnerPidInfo: 
 [com.test.jaservice.entity.PartnerPidEntity@3f7bf0eb]
 [INFO] 29 08 2018 01:35:01:424[PDT] 
 com.test.jaservice.service.partnermanagement.ModifyPartnerServiceImpl 
 modifyPartnerDetailes - PartnerPidInfo: 
[com.quotient.jaservice.entity.PartnerPidEntity@3f7bf0eb]
[INFO] 29 08 2018 01:35:01:425[PDT] 
com.test.jaservice.service.partnermanagement.ModifyPartnerServiceImpl 
insertPartnerPIDInfoEntries - PartnerPidInfo
entry:com.test.jarvisservice.entity.PartnerPidEntity@3f7bf0eb
 [INFO] 29 08 2018 01:35:01:425[PDT] 
com.test.jaservice.service.partnermanagement.ModifyPartnerServiceImpl 
insertPartnerPIDInfoEntries - PartnerPidInfo Key:2ae444f9-b0c6-4714-bfba- 
6120b8a8c6d9|24081
[INFO] 29 08 2018 01:35:01:426[PDT] 
com.test.jaservice.relational.dao.core.DataSourceAspect beforeOMSDB - 
DataSourceAspect invoked
[INFO] 29 08 2018 01:35:01:427[PDT] 
com.test.jaservice.relational.dao.core.DataSourceAspect setDaoContext - 
Environment : DEV
[INFO] 29 08 2018 01:35:01:438[PDT] 
com.test.jaservice.relational.dao.core.ReadWriteAspect before - 
ReadWrite Aspect invoked
[INFO] 29 08 2018 01:35:01:440[PDT] 
com.test.jaservice.relational.dao.core.ReadWriteAspect before - Setting 
read and write access to mariaDB
[INFO] 29 08 2018 01:35:01:440[PDT] 
[INFO] 29 08 2018 01:35:01:441[PDT] 
com.test.jaservice.relational.dao.core.DataSourceRouter 
determineCurrentLookupKey - Read write Environment name: OMSDBDEVW
[ERROR] 29 08 2018 01:35:01:827[PDT]
com.test.jaservice.service.partnermanagement.ModifyPartnerServiceImpl 
insertPartnerPIDInfoEntries - Exception writing into PartnerPidInfo:Class 
must not be null; nested exception is java.lang.IllegalArgumentException: 
Class must not be null
[INFO] 29 08 2018 01:35:01:838[PDT]
com.test.jaservice.rest.controllers.partnermanagement.
ModifyPartnerController modifyPartnerDetailsPOST - Modify Partner was 
Successfull : {2ae444f9-b0c6-4714-bfba-6120b8a8c6d9|24081=Failed}

PartnerPIDEntity

public interface PartnerPIDInfoRepo extends 
 BaseRepository<PartnerPidEntity,String> {

@Transactional(readOnly = true, propagation= Propagation.REQUIRED)
@Query(value="select * from dbo.PartnerPIDInfo where PartnerId = ? 
  1",nativeQuery=true)
List<PartnerPidEntity> findAllPartnerPidInfoEntriesByPartnerId(String 
 partnerId);
}

OMSDBReadWriteWrapper:

 @Service
 public class OMSDBReadWriteWrapper {

@Autowired
private PartnerPIDInfoRepo partnerPidInfoRepo;

public List<PartnerPidInfo> getPartnerPIDInfoEntries(String environment, 
 String partnerId){
    List<PartnerPidEntity> partnerPIDInfoEntities = 
 partnerPidInfoRepo.findAllPartnerPidInfoEntriesByPartnerId(partnerId);
    return mapPartnerPIDInfoEntity(partnerPIDInfoEntities);
  }

 public void insertPartnerPidInfoEntry(String environment, PartnerPidEntity 
 partnerPIDInfoEntity){
    partnerPidInfoRepo.save(partnerPIDInfoEntity);
   }
  }

请帮助我解决此问题。 谢谢

0 个答案:

没有答案