Hi folks,
I have a pretty simple domain model, two entities extending a base AbstractPerson class and I'm using MySQL as my database (Using Roo 1.0.2.Release).
When I run the generated unit tests against this setup, the tests pass successfully.Code:enum type --class ~.reference.TriggeredAction enum constant --name Forward enum constant --name Block entity --class ~.domain.AbstractPerson --abstract entity --class ~.domain.ManagingParent --extends ~.domain.AbstractPerson --testAutomatically entity --class ~.domain.ManagedDependent --extends ~.domain.AbstractPerson --testAutomatically field string --fieldName firstName --sizeMin 3 --sizeMax 30 --class ~.domain.AbstractPerson field string --fieldName lastName --notNull --sizeMin 3 --sizeMax 30 field string --fieldName telephone --notNull --sizeMin 4 field enum --fieldName type --type ~.reference.TriggeredAction --notNull --class ~.domain.ManagedDependent field reference --fieldName managingParent --type ~.domain.ManagingParent field set --class ~.domain.ManagingParent --fieldName managedDependents --element ~.domain.ManagedDependent --mappedBy managingParent --notNull false --cardinality ONE_TO_MANY
However, when I went back and edited the base class to make the telephone field unique I started encountering issues.
The tests started failing due to an issue with duplicate entries being present in the database. So I commented out the unique column constraint and re-ran the test and once again everything passed.Code:@Entity @RooJavaBean @RooToString @RooEntity public abstract class AbstractPerson { @Size(min = 3, max = 30) private String firstName; @NotNull @Size(min = 3, max = 30) private String lastName; @Column(unique = true) @NotNull private String telephone; }
So, my question is, what modifications need to be made to get these tests to pass?
BTW, as an aside and to hopefully help someone in future, when I re-inserted the unique column annotation to the field and re-ran the tests they passed. I was very surprised to say the least. I dropped the table in the MySQL instance and re-ran the test and hey presto, it failed as expected. This occurs I had my hibernate.hbm2ddl.auto property in persistence.xml set to update which did not change the structure of the table in which the entries were stored. If you change the property to create, then the table gets dropped and recreated with the latest structure.


Reply With Quote