[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3822) mysql lack of timestamps with milliseconds breaks hibernate when used with versioning

Thomas Hartwig (JIRA) noreply at atlassian.com
Sat Mar 21 09:21:38 EDT 2009


mysql lack of timestamps with milliseconds breaks hibernate when used with versioning
-------------------------------------------------------------------------------------

                 Key: HHH-3822
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3822
             Project: Hibernate Core
          Issue Type: Improvement
          Components: core
    Affects Versions: 3.3.1
         Environment: mysql-5.1.32-1.fc10
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)

            Reporter: Thomas Hartwig


When I persist an instance with saveOrUpdate into a mysql dbms a version field is kept in milliseconds precision in the current application context. Unfortunately mysql truncates all the milliseconds from this field. So a following merge or any other version based operation fails until the object is refetched.
Possible workarounds:
- use an interceptor for truncating the version field
- avoid using timestamp of mysql

I know the milliseconds problem is really annoying by mysql and it is not a hibernate fault, but probably it can be avoided somehow or hibernate should throw an unsupported exception.

Below is the sample setup:

@Entity
@Table(cname = "_Column")
public class MappedColumn implements Serializable {
   private Date mtime;
   @Version
   public Date getMtime() {
      return mtime;
   }
   public void setMtime(Date mtime) {
      this.mtime = mtime;
   }
   [...]
}


CREATE TABLE `_Column` (
  `name` varchar(255) collate latin1_german1_ci NOT NULL,
  `booleanColumn` bit(1) NOT NULL default '\0',
  `id` varchar(255) collate latin1_german1_ci NOT NULL default '',
  `ctime` datetime default NULL,
  `mtime` datetime default NULL,
  `columnOsc` varchar(255) collate latin1_german1_ci default NULL,
  `columnDbr` int(11) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci;


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list