-->
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.  [ 5 posts ] 
Author Message
 Post subject: Inheritance problem duplicate objects from List
PostPosted: Sun Mar 05, 2006 6:54 am 
Newbie

Joined: Sat Mar 04, 2006 10:07 am
Posts: 9
Hi, have a question about inheritance i hope somebody can help me with. Dont know if it is my mapping or and error. Check question after mapping part.

Using Hibernate version 3.1.2, Hibernate annotations version 3.1beta7
PostgreSql 8.1.3

Mapping is:

Code:
@Entity(access=AccessType.PROPERTY)
@org.hibernate.annotations.Entity(optimisticLock=OptimisticLockType.VERSION)
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Event extends AbstractEntity implements IEvent {
   private Match match;
   
   @ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
   @JoinColumn(name="matchid")
   public Match getMatch() {
      return match;
   }

   public void setMatch(Match match) {
      this.match = match;
   }



Code:
@Entity(access=AccessType.PROPERTY)
@Table(name="startedevents")
public class StartedEvent extends Event {
      private static final long serialVersionUID = -1974642009202477133L;
      private Date timeOfStart;

}


Code:
@Entity(access=AccessType.PROPERTY)
@org.hibernate.annotations.Entity(optimisticLock=OptimisticLockType.VERSION)
@Table(name="matches")
public class Match extends AbstractEntity {
     private List<Event> events = new ArrayList<Event>();

     @OneToMany(mappedBy="match", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
   public List<Event> getEvents() {
      return events;
   }

   public void setEvents(List<Event> events) {
      this.events = events;
   }
}


AbstractEntity is not mapped, tables are created as expected event, startedevent and match. Data is inserted correct, the problem i have is when i create one StartedEvent and add it to the Match events list and persists it. When I load a Match and call its getEvents method it returns 2 equal StartedEvent instances with the same PK.
Is this an error or wrong mapping. Hope somebody can help.

Have implemented equals and hashcode methods in the classes.

_________________
Epllcr


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 9:27 am 
Newbie

Joined: Sat Mar 04, 2006 10:07 am
Posts: 9
Disregard this post the problem was caused by a query that eager fetched more than one collection. With inheritance you can apprantly only be sure that the correct number of objects are returned, when only eager fetching one collection according to Hibernate In Action.

_________________
Epllcr


Top
 Profile  
 
 Post subject: So how do you avoid multiple eager fetch
PostPosted: Fri Mar 31, 2006 2:49 am 
Newbie

Joined: Fri Apr 29, 2005 11:55 pm
Posts: 14
Location: China-Australia
So how do you avoid multiple eager fetch? I got the same problem as yours.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 07, 2006 3:57 am 
Newbie

Joined: Fri Apr 07, 2006 3:50 am
Posts: 3
I have the same problem and the only workaround I've found is to fetch the first collection eagerly, and the second lazy, to iterate through all the elements afterwards (because I need them anyway).
Has anybody found a solution for this?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 16, 2006 12:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Loading more than one collection per query is incredibly evil. So your solution is the right one.


http://opensource.atlassian.com/projects/hibernate/browse/HHH-1413

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.