Spring 将 nvarchar 转换为 bigint 时出错
Spring error converting nvarchar to bigint
每当我尝试保存对象时都会遇到错误。
导致错误的字段是 string
映射到数据库中的 varchar(200)
。
该字段的名称是 localContact
.
这是我的代码:
Site.java:
@Entity
@Table(name = "SITE", uniqueConstraints = { @UniqueConstraint(columnNames = { "SITE_COUNTRY_ID", "SITE_NAME" }) })
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED, withModifiedFlag = true)
public class Site implements ISite {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -390717603276436784L;
/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "SITE_ID", unique = true, nullable = false)
private long id;
/** The site address. */
@Column(name = "SITE_ADDRESS", length = BusinessConstants.SITE_ADDRESS)
private String address;
/** The site analog phone number. */
@Column(name = "SITE_ANALOG_PHONE_NUMBER", length = BusinessConstants.SITE_ANALOG_PHONE_NUMBER)
private String analogPhoneNumber;
/** The site comment. */
@Column(name = "SITE_COMMENT", length = BusinessConstants.SITE_COMMENT)
private String comment;
/** The site entity code. */
@Digits(integer = 3, fraction = 0, message = "Please enter max 3 digits")
@Column(name = "SITE_ENTITY_CODE", nullable = false)
private long entityCode;
/** The site invoice code. */
@Digits(integer = 10, fraction = 0, message = "Please enter max 10 digits")
@Column(name = "SITE_INVOICE_CODE", nullable = false)
private long invoiceCode;
/** The site local it phone. */
@Column(name = "SITE_LOCAL_IT_PHONE", length = BusinessConstants.SITE_LOCAL_IT_PHONE)
private String localItPhone;
/** The site name. */
@NotBlank
@Column(name = "SITE_NAME", nullable = false, length = BusinessConstants.SITE_NAME)
private String siteName;
/** The site subnet. */
@NotBlank
@Column(name = "SITE_SUBNET", nullable = false, length = BusinessConstants.SITE_SUBNET)
private String subnet;
/** The site user number. */
@Digits(integer = 4, fraction = 0, message = "Please enter max 4 digits")
@Column(name = "SITE_USER_NUMBER")
private Long userNumber;
/** The business. */
@Valid
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SITE_BUSINESS_ID", nullable = false)
private Business business;
/** The country. */
@Valid
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "SITE_COUNTRY_ID")
private Country country;
/** The local contact. */
@Column(name = "SITE_LOCAL_CONTACT", nullable = true, length = BusinessConstants.LOCAL_CONTACT)
private String localContact; //the field that cause the error
/** The local it. */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SITE_LOCAL_IT", nullable = true)
private User localIt;
/** The rif. */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SITE_RIF", nullable = true)
private User rif;
/** The status. */
@Valid
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SITE_STATUS_ID", nullable = false)
private Status status;
/** The end date. */
@Column(name = "SITE_END_DATE")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(iso = ISO.DATE_TIME)
private Date endDate = null;
@ManyToMany(targetEntity = User.class, mappedBy = "userSites", fetch = FetchType.LAZY)
@NotAudited
private Set<IUser> siteUsers;
/**
* Gets the local contact.
*
* @return the local contact
*/
public String getLocalContact() {
return this.localContact;
}
/**
* Sets the local contact.
*
* @param localIt the new local contact
*/
public void setLocalContact(String localContact) {
this.localContact = localContact;
}
我的 jsp :
<td class="label"><spring:message code="site.localcontact" /></td>
<td class="value">
<form:input path="site.localContact"></form:input>
</td>
我的 DAO:
public void saveSite(ISite siteObj){
Assert.notNull(siteObj);
merge((Site) siteObj);
}
编辑
抛出的错误是:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type nvarchar to bigint
我发现了错误,
我有另一个 table 为我的站点创建一个名为 SITE_AUD 的历史记录,其中的字段 SITE_LOCAL_CONTACT 是一个 bigint。
每当我尝试保存对象时都会遇到错误。
导致错误的字段是 string
映射到数据库中的 varchar(200)
。
该字段的名称是 localContact
.
这是我的代码:
Site.java:
@Entity
@Table(name = "SITE", uniqueConstraints = { @UniqueConstraint(columnNames = { "SITE_COUNTRY_ID", "SITE_NAME" }) })
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED, withModifiedFlag = true)
public class Site implements ISite {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -390717603276436784L;
/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "SITE_ID", unique = true, nullable = false)
private long id;
/** The site address. */
@Column(name = "SITE_ADDRESS", length = BusinessConstants.SITE_ADDRESS)
private String address;
/** The site analog phone number. */
@Column(name = "SITE_ANALOG_PHONE_NUMBER", length = BusinessConstants.SITE_ANALOG_PHONE_NUMBER)
private String analogPhoneNumber;
/** The site comment. */
@Column(name = "SITE_COMMENT", length = BusinessConstants.SITE_COMMENT)
private String comment;
/** The site entity code. */
@Digits(integer = 3, fraction = 0, message = "Please enter max 3 digits")
@Column(name = "SITE_ENTITY_CODE", nullable = false)
private long entityCode;
/** The site invoice code. */
@Digits(integer = 10, fraction = 0, message = "Please enter max 10 digits")
@Column(name = "SITE_INVOICE_CODE", nullable = false)
private long invoiceCode;
/** The site local it phone. */
@Column(name = "SITE_LOCAL_IT_PHONE", length = BusinessConstants.SITE_LOCAL_IT_PHONE)
private String localItPhone;
/** The site name. */
@NotBlank
@Column(name = "SITE_NAME", nullable = false, length = BusinessConstants.SITE_NAME)
private String siteName;
/** The site subnet. */
@NotBlank
@Column(name = "SITE_SUBNET", nullable = false, length = BusinessConstants.SITE_SUBNET)
private String subnet;
/** The site user number. */
@Digits(integer = 4, fraction = 0, message = "Please enter max 4 digits")
@Column(name = "SITE_USER_NUMBER")
private Long userNumber;
/** The business. */
@Valid
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SITE_BUSINESS_ID", nullable = false)
private Business business;
/** The country. */
@Valid
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "SITE_COUNTRY_ID")
private Country country;
/** The local contact. */
@Column(name = "SITE_LOCAL_CONTACT", nullable = true, length = BusinessConstants.LOCAL_CONTACT)
private String localContact; //the field that cause the error
/** The local it. */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SITE_LOCAL_IT", nullable = true)
private User localIt;
/** The rif. */
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SITE_RIF", nullable = true)
private User rif;
/** The status. */
@Valid
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "SITE_STATUS_ID", nullable = false)
private Status status;
/** The end date. */
@Column(name = "SITE_END_DATE")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(iso = ISO.DATE_TIME)
private Date endDate = null;
@ManyToMany(targetEntity = User.class, mappedBy = "userSites", fetch = FetchType.LAZY)
@NotAudited
private Set<IUser> siteUsers;
/**
* Gets the local contact.
*
* @return the local contact
*/
public String getLocalContact() {
return this.localContact;
}
/**
* Sets the local contact.
*
* @param localIt the new local contact
*/
public void setLocalContact(String localContact) {
this.localContact = localContact;
}
我的 jsp :
<td class="label"><spring:message code="site.localcontact" /></td>
<td class="value">
<form:input path="site.localContact"></form:input>
</td>
我的 DAO:
public void saveSite(ISite siteObj){
Assert.notNull(siteObj);
merge((Site) siteObj);
}
编辑
抛出的错误是:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type nvarchar to bigint
我发现了错误,
我有另一个 table 为我的站点创建一个名为 SITE_AUD 的历史记录,其中的字段 SITE_LOCAL_CONTACT 是一个 bigint。