Results 1 to 6 of 6

Thread: ConstraintViolation when field labeled @NotNull and @OneToOne

  1. #1
    Join Date
    Aug 2011
    Posts
    3

    Default ConstraintViolation when field labeled @NotNull and @OneToOne

    Working on a project with the following:

    Code:
    persistence setup --provider HIBERNATE --database ORACLE
    
    entity --class ~.ItemStatus
    field string --fieldName name --notNull
    
    entity --class ~.ItemState --testAutomatically
    field reference --type ~.ItemStatus status --cardinality ONE_TO_ONE --notNull
    field date --type java.util.Date --fieldName statusDate --notNull
    field boolean --fieldName currentState --notNull
    When I run a mvn compile, I get a notice about failed tests, with the following result:
    Code:
    -------------------------------------------------------------------------------
    Test set: test.ItemStateIntegrationTest
    -------------------------------------------------------------------------------
    Tests run: 9, Failures: 0, Errors: 8, Skipped: 0, Time elapsed: 0.077 sec <<< FAILURE!
    testFlush(test.ItemStateIntegrationTest)  Time elapsed: 0.014 sec  <<< ERROR!
    javax.validation.ConstraintViolationException: Validation failed for classes [test.ItemState] during persist time for groups [javax.validation.groups.Default, ]
    List of constraint violations:[
    	ConstraintViolationImpl{interpolatedMessage='may not be null', propertyPath=status, rootBeanClass=class test.ItemState, messageTemplate='{javax.validation.constraints.NotNull.message}'}
    ]
    	at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:161)
    	at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreInsert(BeanValidationEventListener.java:94)
    	at org.hibernate.action.EntityInsertAction.preInsert(EntityInsertAction.java:178)
    	at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:72)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
            ...
    I'm new to the Spring Roo framework, so I'm probably overlooking something that's obvious to everyone else, but I can't seem to track down a solution for this.

    Any help would be appreciated.

  2. #2
    Join Date
    Mar 2008
    Location
    Sydney, AU
    Posts
    974

    Default

    It appears Roo does not populate the referenced entity in the test case if not null is set. Please raise a Jira ticket so we can fix that.
    Stefan Schmidt
    Software Engineer, Spring Roo
    SpringSource - a division of VMware
    twitter @schmidtstefan

  3. #3
    Join Date
    Dec 2005
    Posts
    930

    Default

    This is working as designed. ItemState requires collaborating data-on-demand metadata from ItemStatus, which you haven't created. To fix your issue, simply execute
    Code:
    dod --entity ~.ItemStatus
    And your tests pass OK
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  4. #4
    Join Date
    Aug 2011
    Posts
    3

    Default

    Added the command supplied above and I'm still running into errors.

    This is what I have currently.

    Code:
    persistence setup --provider HIBERNATE --database ORACLE
    
    entity --class ~.ItemStatus
    field string --fieldName name --notNull --unique
    
    entity --class ~.ItemState --testAutomatically
    field reference --type ~.ItemStatus status --cardinality ONE_TO_ONE --notNull
    dod --entity ~.ItemStatus
    field date --type java.util.Date --fieldName statusDate --notNull
    field boolean --fieldName currentState --notNull
    
    entity --class ~.Item --testAutomatically
    field string --fieldName internalId --notNull --unique
    field string --fieldName description --notNull
    field date --type java.util.Date --fieldName dateReceived --notNull
    field reference --type ~.ItemState --fieldName itemState --cardinality ONE_TO_ONE --notNull
    dod --entity ~.ItemState
    Same errors.

  5. #5
    Join Date
    Dec 2005
    Posts
    930

    Default

    Your script has
    Code:
    dod --entity ~.ItemState
    when I said to do

    Code:
    dod --entity ~.ItemStatus
    You are already creating data on demand for ItemState in the entity command (with --testAutomatically) further up

    Alan
    Alan Stewart
    Spring Roo Committer
    twitter @alankstewart

  6. #6
    Join Date
    Aug 2011
    Posts
    3

    Default

    To clarify, what needed to be done was to run the dod --entity command once for each entity that did not have --testAutomatically appended to its creation.

    It's all working now.

Posting Permissions

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