Grails

Reordering lists do not persist nor cause errors

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Blocker Blocker
  • Resolution: Fixed
  • Affects Version/s: 1.0.1
  • Fix Version/s: 1.0.2
  • Component/s: Persistence
  • Labels:
    None
  • Environment:
    JDK 1.6, Vista
  • Testcase included:
    yes

Description

Test case below. Each is zipped in attachment. Running a Grails app with the files and pointing the browser at http://localhost:8080/test/foo/testChanges
will show the following list:

  • second bar of first foo
  • first bar of first foo

Refreshing the view will continue to show this same list, when it should reverse each time. The println's verify this phenomena. No assertion errors are shown to exist. This demonstrates the view gets a cached version of the reversed Foo.bars list, but doesn't persist the change properly.

class Foo {
String name

List bars
static hasMany = [bars : Bar]

static mapping = {
columns { bars(lazy: false) }
}
}

class Bar {
String name
Foo foo
}

====== in Bootstrap=======

Foo foo = new Foo(name: 'first foo')
foo.addToBars(new Bar(name: 'first bar of first foo'))
foo.addToBars(new Bar(name: 'second bar of first foo'))
foo.save()

====== in FooController=======

def testChanges = {
println '======'

def firstFoo = Foo.get(1)
firstFoo.bars.each {println it.name}
println ''

def bar = firstFoo.bars[0]
firstFoo.bars[0] = firstFoo.bars[1]
firstFoo.bars[1] = bar

firstFoo.bars.each {println it.name}

assert firstFoo.save()

println '======'
}

====== testChanges.gsp=======<html>
<head>
<title>Testing serializing list changes</title>
</head>
<body>
<% def firstFoo = Foo.get(1) %>
<h1>${firstFoo.name}</h1>
<ul>
<g:each var="bar" in="${firstFoo.bars}">
<li>${bar.name}</li>
</g:each>
</ul>
</body>
</html>

Activity

Hide
Graeme Rocher added a comment -

I'm in contact with guys on the Hibernate team about this one, but this process is taking time, hence rolling to next release

Show
Graeme Rocher added a comment - I'm in contact with guys on the Hibernate team about this one, but this process is taking time, hence rolling to next release
Hide
Graeme Rocher added a comment -

Note that this now works for unidirectional associations due to GRAILS-1308

I'm still trying to figure out why it does not work for bidirectional associations, once that happens I'll close the issue

Show
Graeme Rocher added a comment - Note that this now works for unidirectional associations due to GRAILS-1308 I'm still trying to figure out why it does not work for bidirectional associations, once that happens I'll close the issue
Hide
Graeme Rocher added a comment -

Reducing priority as it does work for unidirectional associations at this point

Show
Graeme Rocher added a comment - Reducing priority as it does work for unidirectional associations at this point
Hide
Graeme Rocher added a comment -

fixed for bidirectional relationships now

Show
Graeme Rocher added a comment - fixed for bidirectional relationships now
Hide
Graeme Rocher added a comment -

Bulk closing bunch of resolved issues

Show
Graeme Rocher added a comment - Bulk closing bunch of resolved issues

People

Vote (3)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: