I am trying to upgrade a Grails app from 1.0.3 to 1.3.7 and ran into the exception:
object references an unsaved transient instance - save the transient instance before flushing:
I am not doing any saves in the code that triggers. It is in the following code
public static Season getCurrentSeason() {
String yearString = ConfigurationHolder.config.year
assert yearString != null: "need to configure season"
int year = Integer.parseInt(yearString)
Affiliation nfl = Affiliation.nfl;
return Season.findBySeasonKeyAndLeague(year, nfl)
}
The call to Affiliation.nfl is:
public static Affiliation getNfl() {
if (cacheNFL == null) {
String key = ConfigurationHolder.config.nfl
cacheNFL = Affiliation.findByKey(key)
}
return cacheNFL;
}
If I removed the cacheNFL and make it do a real fetch each time, the code works. My questions are:
- Why did this work before? It seems like making a fetch with a cached object that isn't part of the current Hibernate query (which I am, perhaps incorrectly, assuming is the problem) would never be supported.
- Is there anyway around this problem aside from making a fetch to the database?
- How can I tell if I am hitting the database or going to a Hibernate cache (I don't know much about Hibernate). Is there output that can show me?