• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

problem preventing initialization associated entity

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Message for you sir! I think it is a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic