These are chat archives for hibernate/hibernate-orm

6th
Dec 2016
Hedo Junior
@hedojunior
Dec 06 2016 16:16
Hi, is someone online?
Chris Cranford
@Naros
Dec 06 2016 16:17
@hedojunior Just ask your question and as people are able, we can help.
Hedo Junior
@hedojunior
Dec 06 2016 16:18
So, I'm having an error while mapping, and I couldn't find any other help...
Chris Cranford
@Naros
Dec 06 2016 16:19
What particular error?
Hedo Junior
@hedojunior
Dec 06 2016 16:19
Caused by: org.hibernate.loader.MultipleBagFetchException: cannot simultaneously fetch multiple bags
This is the exception
@OneToOne(fetch = FetchType.LAZY, mappedBy = "token", targetEntity = Usuario.class, cascade = CascadeType.ALL)
private Usuario usuario;
@OneToOne(fetch = FetchType.LAZY, targetEntity = Token.class, cascade = CascadeType.PERSIST)
private Token token;
Chris Cranford
@Naros
Dec 06 2016 16:19
Yep, so you likely have multiple List<?> collections on an entity which you are trying to load eagerly.
Hedo Junior
@hedojunior
Dec 06 2016 16:19
These are my mappings
if i comment the annotation, it works
Chris Cranford
@Naros
Dec 06 2016 16:23
Yep, thats because @OneToOne which use the default optional = true setting cannot be lazily loaded iirc.
Hedo Junior
@hedojunior
Dec 06 2016 16:23
so if i set optional false
it will work?
or do i have to eager load them?
Chris Cranford
@Naros
Dec 06 2016 16:24
afaik, bytecode instrumentation will allow you to apply LAZY nullable one-to-one relations, but without instrumentation you can't.
You can certainly try setting it optional=false, but that means the value cannot be null. Not sure if that applies to your domain model.
Hedo Junior
@hedojunior
Dec 06 2016 16:26
Yeah, it doesn't
maybe the token could have optional false, as it'll always have an user, but the inverse is not possible
Hedo Junior
@hedojunior
Dec 06 2016 16:39
it didn't worked, do you think there's any workaround:
Chris Cranford
@Naros
Dec 06 2016 16:45
@hedojunior not off the top of my head, no.