0

I have an entity Product and inside of entity, i have Contry entity.

When i execute Product.find or Product.get and get country value, my country values has just id value, but in country entity i have id, name and code [id: 1, code:null, name:null], but this situation is intermittently, 99% of time the values are loaded [id:1, code: XXX, name:YYYYY].

I thing this is a cache problem, but i don´t simulate in developer environment, just in production

My Contry domain :

class Country implements Serializable {

private static final long serialVersionUID = 1

def i18NService

String name
String code

static mapping = {
    cache true
}

Country(String code, String name) {
    this()
    this.name = name
    this.code = code
}

This is a grails/hibernate cache bug? How i simulate this situation?

Mister B
  • 123
  • 2
  • 15
  • 1st off all you should define your service in transient block like so: `static transients = [ 'i18NService' ]` – injecteer Oct 13 '18 at 20:30

1 Answers1

0

You did not show your Product domain, so it's hard to say for sure but this sounds like an eager/lazy fetching problem. Basically, a referenced domain object may or may not be fetched along with your another domain object.

You can see documentation here: http://docs.grails.org/latest/ref/Database%20Mapping/lazy.html and there are pretty important performance implications of both eager and lazy fetching, so don't just blindly change this. Basically if you're always going to need Country when get use Product, you should probably make this an eager fetch. If not, you should refresh Country as needed.

Daniel
  • 3,312
  • 1
  • 14
  • 31
  • I running def productList = Product.createCriteria().list (paramsAux) {} productList.each{ print it.country } returns [id:1, code: null, name:null] But is intermittently The real value is returns [id:1, code: BRA, name:Brasil] I don´t know with another request refresh cache or clear value of contry entity. – Mister B Oct 11 '18 at 18:06