0
最近,我在一個基於spring + hibernate的項目中工作。我有兩個實體(ProspectMaster,ProspectWorkshopMap),ProspectMaster與ProspectWorkshopMap有兩個很多的關係,當我添加一個Prospect時,我得到以下錯誤Spring hibernate映射
javax.validation.UnexpectedTypeException:沒有驗證器可以找到類型:java.lang。整數
波紋管是我的代碼
@Entity
public class ProspectMaster {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int prospectID;
private String companyName;
@OneToMany(fetch = FetchType.LAZY, cascade=CascadeType.ALL)
@JoinColumn(name="prospectID")
private Set<ProspectWorkshopMap> prospectWorkshopMap = new HashSet<ProspectWorkshopMap>(0);
public Set<ProspectWorkshopMap> getProspectWorkshopMap() {
return prospectWorkshopMap;
}
public void setProspectWorkshopMap(Set<ProspectWorkshopMap> prospectWorkshopMap) {
this.prospectWorkshopMap = prospectWorkshopMap;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
}
和另一
@Entity
public class ProspectWorkshopMap {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int prospectWorkshopID;
@Column(columnDefinition = "int default 0")
private int iPadProspectWorkshopID;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "prospectCreatedFromID")
private ProspectCreatedFromRef prospectCreatedFromRef;
private String address;
@Length(max = 50)
private String email;
private String deviceID;
@Length(max = 20)
private int directNumber;
private int isMainWorkshop;
@Temporal(TemporalType.TIMESTAMP)
private Date createdDate;
@Temporal(TemporalType.TIMESTAMP)
private Date updatedDate;
private long utcCreatedDateTimestamp;
private long utcUpdatedDateTimestamp;
private int createdBy;
private int updatedBy;
@Column(columnDefinition = "int default 0")
private int isDeleted;
public int getProspectWorkshopID() {
return prospectWorkshopID;
}
public void setProspectWorkshopID(int prospectWorkshopID) {
this.prospectWorkshopID = prospectWorkshopID;
}
public int getiPadProspectWorkshopID() {
return iPadProspectWorkshopID;
}
public void setiPadProspectWorkshopID(int iPadProspectWorkshopID) {
this.iPadProspectWorkshopID = iPadProspectWorkshopID;
}
public ProspectCreatedFromRef getProspectCreatedFromRef() {
return prospectCreatedFromRef;
}
public void setProspectCreatedFromRef(ProspectCreatedFromRef prospectCreatedFromRef) {
this.prospectCreatedFromRef = prospectCreatedFromRef;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDeviceID() {
return deviceID;
}
public void setDeviceID(String deviceID) {
this.deviceID = deviceID;
}
public int getDirectNumber() {
return directNumber;
}
public void setDirectNumber(int directNumber) {
this.directNumber = directNumber;
}
public int getIsMainWorkshop() {
return isMainWorkshop;
}
public void setIsMainWorkshop(int isMainWorkshop) {
this.isMainWorkshop = isMainWorkshop;
}
public Date getCreatedDate() {
return createdDate;
}
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
public Date getUpdatedDate() {
return updatedDate;
}
public void setUpdatedDate(Date updatedDate) {
this.updatedDate = updatedDate;
}
public int getCreatedBy() {
return createdBy;
}
public void setCreatedBy(int createdBy) {
this.createdBy = createdBy;
}
public int getUpdatedBy() {
return updatedBy;
}
public void setUpdatedBy(int updatedBy) {
this.updatedBy = updatedBy;
}
public int getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(int isDeleted) {
this.isDeleted = isDeleted;
}
/**
* @return the utcCreatedDateTimestamp
*/
public long getUtcCreatedDateTimestamp() {
return utcCreatedDateTimestamp;
}
/**
* @param utcCreatedDateTimestamp the utcCreatedDateTimestamp to set
*/
public void setUtcCreatedDateTimestamp(long utcCreatedDateTimestamp) {
this.utcCreatedDateTimestamp = utcCreatedDateTimestamp;
}
/**
* @return the utcUpdatedDateTimestamp
*/
public long getUtcUpdatedDateTimestamp() {
return utcUpdatedDateTimestamp;
}
/**
* @param utcUpdatedDateTimestamp the utcUpdatedDateTimestamp to set
*/
public void setUtcUpdatedDateTimestamp(long utcUpdatedDateTimestamp) {
this.utcUpdatedDateTimestamp = utcUpdatedDateTimestamp;
}
}
救我做
ProspectMaster prospect= new ProspectMaster();
prospect.setCompanyName("Randem IT");
ProspectWorkshopMap prospectWorkshopMap = new ProspectWorkshopMap();
prospectWorkshopMap.setAddress("sydneyaustralia");
prospectWorkshopMap.setCreatedBy(1);
prospectWorkshopMap.setUpdatedBy(1);
prospectWorkshopMap.setDirectNumber(1234567890);
prospectWorkshopMap.setEmail("[email protected]");
prospectWorkshopMap.setIsMainWorkshop(1);
prospectWorkshopMap.setUtcCreatedDateTimestamp(122335);
prospectWorkshopMap.setUtcUpdatedDateTimestamp(86998989);
ProspectCreatedFromRef proRef= new ProspectCreatedFromRef();
proRef.setProspectCreatedFromID(1);
prospect.getProspectWorkshopMap().add(prospectWorkshopMap);
SessionFactory. getCurrentSession().saveOrUpdate(prospect);
我犯錯了嗎?任何人都可以請幫忙。有沒有映射問題?
謝謝trogdor,你的回答真的幫了我很多。你說得對,@ int字段的長度是主要問題。非常感謝。 – RITUser