Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GRAILS-9170 Fix cascading saves on multiple levels

Cascading saves were broken for "multiple levels" with Hibernate 2nd level cache disabled
and using some other id generator than 'identity'.
  • Loading branch information...
commit 635189fbf0a8dc7b996c710b66e635c01e6b4fda 1 parent 3cc9e52
@lhotari lhotari authored
View
2  .../src/main/groovy/org/codehaus/groovy/grails/orm/hibernate/support/ClosureEventTriggeringInterceptor.java
@@ -271,7 +271,7 @@ protected Serializable performSaveOrReplicate(Object entity, EntityKey key, Enti
if (!useIdentityColumn) {
EntityInsertAction insert = new EntityInsertAction(id, values, entity, version, persister, source);
source.getActionQueue().execute(insert);
- if(!source.getPersistenceContext().wasInsertedDuringTransaction(persister, id)) {
+ if(persister.hasCache() && !source.getPersistenceContext().wasInsertedDuringTransaction(persister, id)) {
insertVetoed=true;
}
}
View
75 .../test/groovy/org/codehaus/groovy/grails/orm/hibernate/CascadingSaveAndNonIdentityGeneratedIdTests.groovy
@@ -0,0 +1,75 @@
+package org.codehaus.groovy.grails.orm.hibernate
+
+class CascadingSaveAndNonIdentityGeneratedIdTests extends AbstractGrailsHibernateTests {
+
+ protected void onSetUp() {
+ gcl.parseClass '''
+package cascadingsave
+
+import grails.persistence.Entity
+
+@Entity
+class Request {
+ static hasMany = [samples: Sample]
+
+ Date dateCreated
+ Date lastUpdated
+
+ static mapping = {
+ cache false
+ id generator: 'increment'
+ }
+}
+
+@Entity
+class Sample {
+ static belongsTo = [request : Request]
+ static hasMany = [attributes: Attribute]
+
+ static mapping = {
+ cache false
+ id generator: 'increment'
+ }
+}
+
+@Entity
+class Attribute {
+ static belongsTo = [sample : Sample]
+
+ static mapping = {
+ cache false
+ id generator: 'increment'
+ }
+}
+'''
+ println "Parsed!"
+ }
+
+ void testCascadingSaveToMultipleLevels() {
+ def requestClass = ga.getDomainClass("cascadingsave.Request").clazz
+ def sampleClass = ga.getDomainClass("cascadingsave.Sample").clazz
+ def attributeClass = ga.getDomainClass("cascadingsave.Attribute").clazz
+
+ def request = requestClass.newInstance()
+
+ 10.times {
+ def sample = sampleClass.newInstance()
+ request.addToSamples(sample)
+ 10.times {
+ sample.addToAttributes(attributeClass.newInstance())
+ }
+ }
+
+ request.save(flush:true)
+
+ requestClass.withNewSession {
+ def savedRequest = requestClass.get(request.id)
+ assert savedRequest.samples.size() == 10
+ savedRequest.samples.each {
+ assert it.attributes.size() == 10
+ }
+ }
+
+
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.