-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Many to One bi-directional loading problem
PostPosted: Tue Mar 04, 2008 10:19 am 
Newbie

Joined: Tue Mar 04, 2008 9:53 am
Posts: 2
Hibernate version: 3.2.4.sp1

Name and version of the database you are using: Oracle 10g

I have a stange loading issue with hibernate entity manager (jboss 4.2.2GA).
I have a many to one bi-directional relationship set up:

Code:

GameGroup.java:

...
@OneToMany(fetch = FetchType.EAGER, mappedBy="gameGroup", cascade = CascadeType.ALL)
  private Set<GameSubGroup> gameSubGroups = new HashSet<GameSubGroup>();
...

GameSubGroup.java
...
  @ManyToOne(optional=false)
  @JoinColumn(name="gameGroupId")
  private GameGroup gameGroup;
...


and I have used the UUID approach to equals and hashCode which works an absolute treat. I have a previously created a GameGroup that has two GameSubGroups and when you do this (from a clean entity manager):


Code:
GameSubGroup gameSubGroup = entityManager.find(GameSubGroup.class, gameSubGroupId);


This:

Code:
  gameSubGroup.getGameGroup().getGameSubGroups().contains(gameSubGroup);


resolves to false...

I've debugged it and the getGameSubGroups() collection does contain the gameSubGroup as expected (same Id and UUID).

I've traced through the code and I've found that when the entityManager is looking up the GameSubGroup two calls are made to hashCode with empty (newly instantiated) GameSubGroup's. It looks as if these newly created objects are being added to the GameGroup's HashSet before they have been loaded with the data from the DB (and hence the UUID). This also means that calling remove() on the GameGroup's collection with a GameSubGroup fails (which is how I found the problem).

You can work around the problem by looking up the owning GameGroup first in effect pre-loading the entity manager.

Is this a bug with loading from the non-owning side of a relationship or have I missed something?


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 07, 2008 1:50 pm 
Newbie

Joined: Tue Mar 04, 2008 9:53 am
Posts: 2
I've also tried it with the latest (production) versions of hibernate and entity manager (3.2.6GA and 3.3.1GA) with the same result. Shall I report this as a bug?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.