Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...g/codehaus/groovy/grails/orm/hibernate/CascadingSaveAndNonIdentityGeneratedIdTests.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 | |||
} | |||
} | |||
|
|||
|
|||
} | |||
} |