Results 1 to 3 of 3

Thread: Timestamp Field as Entity Version

  1. #1
    Join Date
    Oct 2007
    Location
    Albany, NY
    Posts
    16

    Default Timestamp Field as Entity Version

    I have created an entity using "new persistent class jpa", I then modified the entity to use a last updated field as the version by adding the following to the .java file generated for the entity:

    Code:
        @Version
        @NotNull
        @Temporal(TemporalType.TIMESTAMP)
        @Column(name="UPDATE_DATE", nullable=false)
        private Date updateDate;
        
        public java.util.Date getUpdateDate() {    
            return this.updateDate;        
        }    
        
        public void setUpdateDate(java.util.Date updateDate) {    
            this.updateDate = updateDate;        
        }
    This updated all the .aj files correctly, but then I used "new integration test" to generate an integration test, and in the Roo_IntegrationTest.aj file two of the generate methods were:

    Code:
        @org.junit.Test    
        @org.springframework.transaction.annotation.Transactional    
        public void testFlush() {    
            junit.framework.Assert.assertNotNull("Data on demand for 'Cycle' failed to initialize correctly", dod.getRandomCycle());        
            java.lang.Long id = dod.getRandomCycle().getId();        
            junit.framework.Assert.assertNotNull("Data on demand for 'Cycle' failed to provide an identifier", id);        
            gov.ny.dec.saeas.Cycle obj = gov.ny.dec.saeas.Cycle.findCycle(id);        
            junit.framework.Assert.assertNotNull("Find method for 'Cycle' illegally returned null for id '" + id + "'", obj);        
            boolean modified =  dod.modifyCycle(obj);        
            java.util.Date currentVersion = obj.getUpdateDate();        
            obj.flush();        
            junit.framework.Assert.assertTrue("Version for 'Cycle' failed to increment on flush directive", obj.getUpdateDate() > currentVersion || !modified);        
        }    
        
        @org.junit.Test    
        @org.springframework.transaction.annotation.Transactional    
        public void testMerge() {    
            junit.framework.Assert.assertNotNull("Data on demand for 'Cycle' failed to initialize correctly", dod.getRandomCycle());        
            java.lang.Long id = dod.getRandomCycle().getId();        
            junit.framework.Assert.assertNotNull("Data on demand for 'Cycle' failed to provide an identifier", id);        
            gov.ny.dec.saeas.Cycle obj = gov.ny.dec.saeas.Cycle.findCycle(id);        
            junit.framework.Assert.assertNotNull("Find method for 'Cycle' illegally returned null for id '" + id + "'", obj);        
            boolean modified =  dod.modifyCycle(obj);        
            java.util.Date currentVersion = obj.getUpdateDate();        
            obj.merge();        
            obj.flush();        
            junit.framework.Assert.assertTrue("Version for 'Cycle' failed to increment on merge and flush directive", obj.getUpdateDate() > currentVersion || !modified);        
        }
    The on the last line of each method, the code which reads:
    Code:
    obj.getUpdateDate() > currentVersion
    Should be:
    Code:
    obj.getUpdateDate().after(currentVersion)
    A work around is to copy the methods to the .java file and make the required change, which will remove the methods from the .aj file. I will log a Jira issue for this.

  2. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    Hi Chris,

    This looks like something we can fix . Thanks for opening the Jira ticket to track this.

    Cheers,
    Stefan

  3. #3
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    For those who discover this thread in the future, http://jira.springsource.org/browse/ROO-83 has now been fixed and will be included in Roo 1.0.0.M2.
    Ben Alex
    Project Founder, Spring UAA, Spring Roo and Spring Security

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •