0
votes

This is in grails 2.5.6 code. I have a domain class that uses inheritance. One of the subclasses contains a list of strings stored in the variable values. When calling .save(), the domain class itself saves correctly with the right inheritance behavior, but the values do not get saved. Here is my domain classes:

abstract class Condition implements ICondition, IMarshaler {
    String field;
    static mapping = {
        tablePerHierarchy false;
    }
    ...
}

class ListCondition extends Condition {
    static hasMany = [values: String];
    List<String> values;
    ...
}

Attempting to save a new list condition and the getting it again from the database shows that there is no values.

ListCondition condition = new ListCondition(field: 'someField', values: ['test', 'otherTest'])
condition.save()
println ListCondition.getAll()[0].values.size() // Prints 0
1
try condition.save(failOnError: true) which will give you some stacktrace if there's an error - chim

1 Answers

0
votes

Stumbled upon a similar issue. Try condition.save(flush: true) or even better try running your persistence-logic inside a transaction. This seems to make the difference and is considered best-practice anyways.