Announcement Announcement Module
Collapse
No announcement yet.
Data On Demand Problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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, 07:59 PM.

      Comment


      • #4
        Raised https://jira.springsource.org/browse/ROO-2523 and resolved. Please try.

        Comment


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

          Comment


          • #6
            Thanks Mr. Stewart. Top notch!

            Comment


            • #7
              Thanks Alan for fixing this so swiftly.

              Comment


              • #8
                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?

                Comment


                • #9
                  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'

                  Comment

                  Working...
                  X