Results 1 to 9 of 9

Thread: Data On Demand Problem

  1. #1
    Join Date
    Sep 2005
    Posts
    25

    Default Data On Demand Problem

    Hi,

    First of all I have a Vehicle domain class where one of the fields is defined thus

    Code:
        @NotNull
        @Column(unique = true)
        @Size(min = 8, max = 8)
        private String registration;
    Note the that registration field is defined as being unique.

    Looking at the inetgration test that Roo has created for me you will see that it is trying to persist a new Vehicle

    Code:
        @Test
        public void VehicleIntegrationTest.testPersist() {
            org.junit.Assert.assertNotNull("Data on demand for 'Vehicle' failed to initialize correctly", dod.getRandomVehicle());
            uk.co.steria.telematrix.server.domain.Vehicle obj = dod.getNewTransientVehicle(Integer.MAX_VALUE);
            org.junit.Assert.assertNotNull("Data on demand for 'Vehicle' failed to provide a new transient entity", obj);
            org.junit.Assert.assertNull("Expected 'Vehicle' identifier to be null", obj.getId());
            obj.persist();
            obj.flush();
            org.junit.Assert.assertNotNull("Expected 'Vehicle' identifier to no longer be null", obj.getId());
        }
    Up to the point where the new Vehicle obj is created a number of vehicles have already been created as part of the initialisation of this test. You can see above that MAX_VALUE (which is 2147483647) is used to create the Vehicle obj.

    The generated code below from VehicleDataOnDemand_Roo_DataOnDemand sets the registration field.

    Code:
        public void VehicleDataOnDemand.setRegistration(Vehicle obj, int index) {
            java.lang.String registration = "regist_" + index;
            if (registration.length() > 8) {
                registration = registration.substring(0, 8);
            }
            obj.setRegistration(registration);
        }
    The problem is that because this field is 8 chars in length the field is set to the value "regist_2" (number taken from first character of MAX_VALUE - 2147483647) and regist_2 has already been set during initialisation of this test, therefore a unique contraint violation is thrown.

    Is this a problem or am I doing something wrong?

    Many Thanks

    Ted

  2. #2
    Join Date
    May 2011
    Posts
    17

    Default

    Hi Ted, I had a similar problem with DataOnDemand and an @Email constraint. It simply doesn't support all constraints, and it seems to silently ignore them. I had many constraints in my class and had an interested experience trying to sort out which one was failing. I was assuming it was one of the @NotNull @ManyToOne fields, but no, simply an improperly formatted email field.

  3. #3
    Join Date
    Dec 2005
    Posts
    930

    Default

    This is a limitation of DoD at the moment. Also we don't support the @Email constraint nor all corner cases of the validation annotations. Please raise a Jira ticket for this particular issue and I should be able to fix it before 1.1.5 comes out on the 7th July
    Last edited by Alan Stewart; Jun 25th, 2011 at 06:59 PM.
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  4. #4
    Join Date
    Dec 2005
    Posts
    930

    Default

    Raised https://jira.springsource.org/browse/ROO-2523 and resolved. Please try.
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  5. #5
    Join Date
    Dec 2005
    Posts
    930

    Default

    Added basic support for @Email annotated fields in https://jira.springsource.org/browse/ROO-2524. This support is quite simple so if you also add size constraints to the email column you may get strange results. The ORM does the validation and it seems only a "@" character is required to make it a valid email address.
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  6. #6
    Join Date
    May 2011
    Posts
    17

    Default

    Thanks Mr. Stewart. Top notch!

  7. #7
    Join Date
    Sep 2005
    Posts
    25

    Default

    Thanks Alan for fixing this so swiftly.

  8. #8
    Join Date
    Nov 2011
    Posts
    7

    Question Data On Demand with @NotNull references to other entitiy unpredictable

    Hi,
    I have problem with dod test generation for class that has @NotNull reference field to another @RooEntity marked class. I can never guess when it will generate reference to other dod generated class.
    In my example:
    Code:
    @RooEntity ....
    class Profile{
        @NotNull
        @OneToOne
        private AppUser appUser;
    }
    
    @RooEntity ...
    class AppUser{
        @OneToOne(mappedBy = "appUser", cascade = CascadeType.REMOVE)
        private Profile profile
    }
    In ProfileUserDataOnDemand_Roo_DataOnDemand.aj it generates member to get data for AppUser
    Code:
    ...    
        private List<Profile> ProfileDataOnDemand.data;
        @Autowired
        private AppUserDataOnDemand ProfileDataOnDemand.appUserDataOnDemand;
    ...
        public void ProfileDataOnDemand.setAppUser(Profile obj, int index) {
            AppUser appUser = appUserDataOnDemand.getSpecificAppUser(index);
            obj.setAppUser(appUser);
        }
    ...
    Now this works, but sometimes it does not generate reference to AppUser dod class and sets appUser to null, which results in failed test. All domain classes were complete before generating tests, but it really should not matter since test are continuously updated.
    So, now I have the same problem with class Message having
    Code:
    class Message{
       @NotNull
       @OneToOne
       AppUser sender;
    }
    class AppUser{
    //no reference to Message
    }
    reference, and dod class for Message does not generate dod field for AppUser.
    Should I just start hardcoding those references and setting method in dod classes?

  9. #9
    Join Date
    Nov 2011
    Posts
    7

    Default bidirectional relations fail for dod generation

    Roo 1.2.0.RC1 throws exception consistently. This is for bidirectional relation OneToMany and ManyToOne for dod generation classes. The problem is that it also conflicts with non-tested classes and aspects.

    java.lang.IllegalArgumentException: Invalid dependency between upstream'MID:org.springframework.roo.addon.dod.Dat aOnDem
    andMetadata#SRC_TEST_JAVA?com.hottenup.server.doma in.ProfileDataOnDemand' and downstream'MID:org.springframework.roo.addon.dod.D ataOnDemandMetadata#SRC_TEST_JAVA?com.hottenup.ser ver.domain.ImageDataOnDemand'

Posting Permissions

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