| Author |
problem preventing initialization associated entity
|
Alexander Curvers
Greenhorn
Joined: Apr 03, 2009
Posts: 26
|
|
hi i have an entity A with a OneToOne bidirectional relation/association with an entity B
when i query for all entities of type A i also get all B entities, while on both sides the annotation fetchtype = lazy... anyone know why this happens/how to prevent it ?
tnx
@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
Indeed, this shouldn't be happening.
My first question is 'how do you know you are getting all entities of type B?' What's your proof?
How you know you have a good proof?
-Cameron McKenzie
|
Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
|
 |
Alexander Curvers
Greenhorn
Joined: Apr 03, 2009
Posts: 26
|
|
Cameron Wallace McKenzie wrote:Indeed, this shouldn't be happening.
My first question is 'how do you know you are getting all entities of type B?' What's your proof?
How you know you have a good proof?
-Cameron McKenzie
ok i step through my code using the debugger when i get to the code where on the entitymanager the query "from A" is executed.. i see in my console (hybernate sql debug logging enabled) hundreds of queries flying by for entity B with a reference of PK of entity A.. this sql statements for entity B keep flying by in the console until a timeout occurs ... (so i dont get my entity A at all)
(btw database contains like 3000 of entity A and about 3000 of entity B)
i dont know why entity B is fetched (and i dont need them fetched).. the query on the entitymangager, is like above, plain and simple... the query is not the problem
so i think it has to do with the definition of the entity A or the definition of entity B
but would not know what the problem could be because like i said both are just @OneToOne with fetchtyp lazy...
and i checked for other references from one to the other but cant find any..
|
 |
Benjamin Winterberg
Ranch Hand
Joined: Sep 19, 2007
Posts: 36
|
|
Have you read the chapter about single ended association proxies?
http://docs.jboss.org/hibernate/stable/core/reference/en/html/performance.html#performance-fetching-proxies
Perhaps there is a case where hibernate cannot create a proxy so hibernate forces to eagerly load the association.
|
Hibernate DAOs with Spring | Separation of Concerns | Eclipse Code Templates | more...
|
 |
Alexander Curvers
Greenhorn
Joined: Apr 03, 2009
Posts: 26
|
|
i found the solution after all
i have removed the mappedby from the relationship now the B's are not all loaded :S
anyone can explain to me why they where loaded in the first place ?
|
 |
 |
|
|
subject: problem preventing initialization associated entity
|
|
|