Announcement Announcement Module
Collapse
No announcement yet.
Timestamp Field as Entity Version Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Hi Chris,

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

    Cheers,
    Stefan

    Comment


    • #3
      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.

      Comment

      Working...
      X