I'm getting some caching when I fetch inverseMany relations
I have:
class User extends Record[Long, User] with IdentityGenerator[Long, User] {
val id = "id".BIGINT.NOT_NULL.AUTO_INCREMENT
def comments = inverseMany(Comment.owner)
def devices = inverseMany(Device.owner)
def documents = inverseMany(Document.owner)
def PRIMARY_KEY = id
def relation = User
}
and corresponding Device, Document, Comment classes with
lazy val owner = "owner_id".BIGINT.REFERENCES(User).ON_DELETE(CASCADE)
When I run this code:
Context.executeInNew { ctx =>
val u = User.find(1);
Logger.info("" + u.documents.item.size) // should be 4
Logger.info("" + u.devices.item.size) // should be 1
Logger.info("" + u.comments.get.size) // should be 0
}
I get
4
4
4
Whichever item is first seems to cache.
Also if i try u.documents.get.map(d => ...)
and then u.devices.get.map(d => ...) i get a
ClassCastException: models.Document cannot be cast to models.Device at run time (again, whichever relationship runs first seems to cache.
wrapping each statement in its own Context.executeInNew { ctx => ...} fixes it, but should this be the case or am I missing something obvious?
Any help would be much appreciated.