Grails
  1. Grails
  2. GRAILS-8747

Saving many-to-many in unit test causes stack overflow

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0 final
    • Fix Version/s: 2.0.1
    • Component/s: Testing
    • Labels:
      None
    • Testcase included:
      yes

      Description

      Given these two domains:

      class Book {
          static hasMany = [invoices: Invoice]
      }
      
      class Invoice {
          static belongsTo = [Book]
          static hasMany = [books: Book]
      }
      

      I run this unit test:

      @TestFor(Book)
      @Mock([Book, Invoice])
      class BookTests {
      
          void testSave() {
              Book book = new Book().save()
              assert book
      
              book.addToInvoices(new Invoice())
              book.save()
          }
      }
      

      and this exception is thrown at the save call:

      java.lang.StackOverflowError
      	at java.util.WeakHashMap.expungeStaleEntries(WeakHashMap.java:274)
      	at java.util.WeakHashMap.getTable(WeakHashMap.java:302)
      	at java.util.WeakHashMap.get(WeakHashMap.java:349)
      	at java.util.Collections$SynchronizedMap.get(Collections.java:1975)
      	at org.grails.datastore.mapping.engine.EntityAccess.getProperty(EntityAccess.java:62)
      	at org.grails.datastore.mapping.engine.EntityAccess.getIdentifier(EntityAccess.java:76)
      	at org.grails.datastore.mapping.engine.EntityPersister.getObjectIdentifier(EntityPersister.java:101)
      	at org.grails.datastore.mapping.core.AbstractSession.isDirty(AbstractSession.java:264)
      	at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntity(NativeEntryEntityPersister.java:670)
      	at org.grails.datastore.mapping.engine.EntityPersister.persist(EntityPersister.java:130)
      	at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntities(NativeEntryEntityPersister.java:1192)
      	at org.grails.datastore.mapping.engine.EntityPersister.persist(EntityPersister.java:134)
      	at org.grails.datastore.mapping.core.AbstractSession.persist(AbstractSession.java:642)
      	at org.grails.datastore.mapping.simple.engine.SimpleMapEntityPersister.setManyToMany(SimpleMapEntityPersister.groovy:187)
      	at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntity(NativeEntryEntityPersister.java:776)
      	at org.grails.datastore.mapping.engine.EntityPersister.persist(EntityPersister.java:130)
      	at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntities(NativeEntryEntityPersister.java:1192)
      	at org.grails.datastore.mapping.engine.EntityPersister.persist(EntityPersister.java:134)
      	at org.grails.datastore.mapping.core.AbstractSession.persist(AbstractSession.java:642)
      	at org.grails.datastore.mapping.simple.engine.SimpleMapEntityPersister.setManyToMany(SimpleMapEntityPersister.groovy:187)
      	at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntity(NativeEntryEntityPersister.java:776)
      	at org.grails.datastore.mapping.engine.EntityPersister.persist(EntityPersister.java:130)
      	at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntities(NativeEntryEntityPersister.java:1192)
      	at org.grails.datastore.mapping.engine.EntityPersister.persist(EntityPersister.java:134)
      	at org.grails.datastore.mapping.core.AbstractSession.persist(AbstractSession.java:642)
      	at org.grails.datastore.mapping.simple.engine.SimpleMapEntityPersister.setManyToMany(SimpleMapEntityPersister.groovy:187)
      	at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntity(NativeEntryEntityPersister.java:776)
      	at org.grails.datastore.mapping.engine.EntityPersister.persist(EntityPersister.java:130)
      	at org.grails.datastore.mapping.engine.NativeEntryEntityPersister.persistEntities(NativeEntryEntityPersister.java:1192)
      	at org.grails.datastore.mapping.engine.EntityPersister.persist(EntityPersister.java:134)
      

        Activity

        Show
        Graeme Rocher added a comment - Fixed by https://github.com/SpringSource/grails-data-mapping/commit/5ec14cadc72efdc94afd261a751703d6f589d1ee

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            Matt Sheehan
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development