Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem preventing initialization associated entity

 
Alexander Curvers
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Alexander Curvers
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alexander Curvers
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic