I have a J2EE web application utilizing Hibernate 3.3 and JPA. This is not a Spring application. I am using JBoss v4.2.3.GA, MySQL v5.6.10 and MySQL connector v3.1.13. This is running with Java v1.6. I develop using MyEclipse v10 which is based on Eclipse v3.7.2.
This application has been running in production for several years now and still runs just fine. However, I recently started a new project on my development machine and have run into an extremely frustrating problem. I have several tables that contain a Timestamp field. If my code attempts to update any table with a Timestamp field I get a truncation error on the Timestamp field. I have not changed JBoss, MySQL, Java or any of the code. The application worked great just a few weeks ago. The only significant action taken on my machine is a Windows 7 update.
I usually test within the MyEclipse environment but have even tried closing down MyEclipse and starting JBoss normally as a service with no change in the result.
An example of the failure is as follows:
The table is defined as
Code:
use xyz;
CREATE TABLE `account_tbl` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`website_url` varchar(255) DEFAULT NULL,
`date_joined` date NOT NULL,
`last_activity_date` date NOT NULL,
`industry_role_id` int(11) unsigned NOT NULL DEFAULT '0',
`acct_type` tinyint(4) DEFAULT '-1',
`status` tinyint(3) unsigned NOT NULL DEFAULT '0',
`description` text,
`last_labor_rpt_date` timestamp NULL DEFAULT NULL,
`labor_alt_descr` text,
`fee_paid` decimal(8,2) DEFAULT '0.00',
`date_paid` date DEFAULT NULL,
`due_date` date DEFAULT NULL,
`contr_type` char(1) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `account_name_idx` (`name`),
KEY `FK_ACCT_INDROLE` (`industry_role_id`),
CONSTRAINT `FK_ACCT_INDROLE` FOREIGN KEY (`industry_role_id`) REFERENCES `admin_industry_role_tbl` (`id`) ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
The table is described in Hibernate annotation as
Code:
Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "industry_role_id", nullable = false)
public AdminIndustryRoleTbl getAdminIndustryRoleTbl() {
return this.adminIndustryRoleTbl;
}
public void setAdminIndustryRoleTbl(AdminIndustryRoleTbl adminIndustryRoleTbl) {
this.adminIndustryRoleTbl = adminIndustryRoleTbl;
}
@Column(name = "name", unique = true, nullable = false)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "status", nullable = false)
public Integer getStatus() {
return this.status;
}
public void setStatus(Integer status) {
this.status = status;
}
@Column(name = "acct_type", nullable = false)
public Integer getAcctType() {
return this.acctType;
}
public void setAcctType(Integer acctType) {
this.acctType = acctType;
}
@Column(name = "contr_type", nullable = true)
public String getContrType() {
return this.contrType;
}
public void setContrType(String contrType) {
this.contrType = contrType;
}
@Column(name = "website_url")
public String getWebsiteUrl() {
return this.websiteUrl;
}
public void setWebsiteUrl(String websiteUrl) {
this.websiteUrl = websiteUrl;
}
@Temporal(TemporalType.DATE)
@Column(name = "date_joined", nullable = false, length = 10)
public Date getDateJoined() {
return this.dateJoined;
}
public void setDateJoined(Date dateJoined) {
this.dateJoined = dateJoined;
}
@Temporal(TemporalType.DATE)
@Column(name = "last_activity_date", nullable = false, length = 10)
public Date getLastActivityDate() {
return this.lastActivityDate;
}
public void setLastActivityDate(Date lastActivityDate) {
this.lastActivityDate = lastActivityDate;
}
@Column(name = "fee_paid", precision=8, scale=2)
public BigDecimal getFeePaid() {
return feePaid;
}
public void setFeePaid(BigDecimal feePaid) {
this.feePaid = feePaid;
}
@Temporal(TemporalType.DATE)
@Column(name = "date_paid", nullable = true, length = 10)
public Date getDatePaid() {
return datePaid;
}
public void setDatePaid(Date datePaid) {
this.datePaid = datePaid;
}
@Temporal(TemporalType.DATE)
@Column(name = "due_date", nullable = true, length = 10)
public Date getNextDueDate() {
return nextDueDate;
}
public void setNextDueDate(Date nextDueDate) {
this.nextDueDate = nextDueDate;
}
@Column(name = "description", length = 65535)
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
@Column(name = "last_labor_rpt_date", length = 19)
public Timestamp getLastLaborRptDate() {
return this.lastLaborRptDate;
}
public void setLastLaborRptDate(Timestamp lastLaborRptDate) {
this.lastLaborRptDate = lastLaborRptDate;
}
@Column(name = "labor_alt_descr", length = 65535)
public String getLaborAltDescr() {
return this.laborAltDescr;
}
public void setLaborAltDescr(String laborAltDescr) {
this.laborAltDescr = laborAltDescr;
}
When the application attempts to update this table I receive the following error
Quote:
[JDBCExceptionReporter] Data truncation: Incorrect timestamp value: '' for column 'last_labor_rpt_date' at row 1
I installed log4jdbc and can now see the actual SQL that is used. Here is the statement that is failing
Code:
update xyz.account_tbl set acct_type=1, industry_role_id=18, contr_type='N',
date_joined='2008-11-10', date_paid=NULL, description=NULL, fee_paid=0.00, labor_alt_descr='',
last_activity_date='2013-05-22', last_labor_rpt_date='2013-05-22 17:55:05', name='Test Account',
due_date='2013-01-31', status=1, website_url='www.test.com' where id=71;
I even cut that statement out of the log and pasted in MySQL Workbench and it updated with no problem.
I don't know now what else to do to debug this. I have Googled for 2 days and tried just about everything including adding the annotation
@Temporal(TemporalType.TIMESTAMP) and adding
columnDefinition = "timestamp" to the @column statement with no change.
I really need help on this one.