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