How do I clear and replace a collection in a one-to-many relationship in Grails/Groovy

前端 未结 4 618
耶瑟儿~
耶瑟儿~ 2021-02-14 06:13

This question is in two parts, first part is about clearing a list and second part is about assigning an owner to an object.

I have a one-to-many relationship between tw

4条回答
  •  感情败类
    2021-02-14 06:42

    Clearing Collection approach didn't worked for me:

    activePerson.locations.clear()
    

    Just try iterate over collection with avoiding ConcurrentModificationException by calling collect():

    activePerson.locations.collect().each {
        item.removeFromLocations(it)
    }
    

    And after that save the entity to execute SQL statement:

    activePerson.save flush:true
    

    Link to article to read more: http://spring.io/blog/2010/07/02/gorm-gotchas-part-2/

提交回复
热议问题