Skip to content

Commit 69dc899

Browse files
committed
Merged fix for GRAILS-4344 which also fixes GRAILS-5426 "HibernatePluginSupport.#addValidationMethods(...) is reason of memory leak"
1 parent 6f4936c commit 69dc899

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed

src/groovy/org/codehaus/groovy/grails/orm/hibernate/support/ClosureEventTriggeringInterceptor.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class ClosureEventTriggeringInterceptor extends SaveOrUpdateEventListener implem
135135
entity."$property.name" = now
136136
}
137137

138+
if(!entity.validate(deepValidate:false)) {
139+
result = true
140+
}
138141
return result
139142
}
140143

src/groovy/org/codehaus/groovy/grails/plugins/DomainClassGrailsPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DomainClassGrailsPlugin {
3333

3434
def version = grails.util.GrailsUtil.getGrailsVersion()
3535
def dependsOn = [i18n:version]
36-
def loadAfter = ['hibernate', 'controllers']
36+
def loadAfter = ['controllers']
3737

3838
def doWithSpring = {
3939
for(dc in application.domainClasses) {

src/groovy/org/codehaus/groovy/grails/plugins/orm/hibernate/HibernatePluginSupport.groovy

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,6 @@ Try using Grails' default cache provider: 'org.hibernate.cache.OSCacheProvider'"
394394
Validator validator = ctx.containsBean("${dc.fullName}Validator") ? ctx.getBean("${dc.fullName}Validator") : null
395395
def validateMethod = new ValidatePersistentMethod(sessionFactory, application.classLoader, application,validator)
396396

397-
MetaProperty originalPropertiesProperty = metaClass.getMetaProperty("properties")
398-
metaClass.setProperties = {Object o ->
399-
originalPropertiesProperty.setProperty delegate, o
400-
if(delegate.hasErrors()) {
401-
GrailsHibernateUtil.setObjectToReadyOnly delegate,sessionFactory
402-
}
403-
}
404-
405397
metaClass.validate = {->
406398
validateMethod.invoke(delegate, "validate", [] as Object[])
407399
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.codehaus.groovy.grails.orm.hibernate
2+
/**
3+
* @author Graeme Rocher
4+
* @since 1.1
5+
*/
6+
7+
public class DoNotPersistInvalidObjectTests extends AbstractGrailsHibernateTests{
8+
9+
protected void onSetUp() {
10+
gcl.parseClass('''
11+
import grails.persistence.*
12+
13+
@Entity
14+
class DoNotPersist {
15+
String name
16+
17+
static constraints = {
18+
name size:1..5
19+
}
20+
}
21+
''')
22+
}
23+
24+
25+
void testDoNoPersistInvalidInstanceUsingDirtyChecking() {
26+
def testDomain = ga.getDomainClass("DoNotPersist").clazz
27+
28+
def t = testDomain.newInstance(name:"bob")
29+
30+
assertNotNull "should have saved test instance",t.save(flush:true)
31+
32+
session.clear()
33+
34+
t = testDomain.get(1)
35+
t.name = "fartooolong"
36+
37+
session.flush()
38+
session.clear()
39+
40+
t = testDomain.get(1)
41+
assertEquals "bob", t.name
42+
}
43+
44+
void testPersistValidInstanceUsingDirtyChecking() {
45+
def testDomain = ga.getDomainClass("DoNotPersist").clazz
46+
47+
def t = testDomain.newInstance(name:"bob")
48+
49+
assertNotNull "should have saved test instance",t.save(flush:true)
50+
51+
session.clear()
52+
53+
t = testDomain.get(1)
54+
t.name = "fred"
55+
56+
session.flush()
57+
session.clear()
58+
59+
t = testDomain.get(1)
60+
assertEquals "fred", t.name
61+
}
62+
63+
}

0 commit comments

Comments
 (0)