-->
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/question duplicate objects from List
PostPosted: Sat Mar 04, 2006 10:51 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: Mon Mar 06, 2006 9:00 am 
Newbie

Joined: Sat Mar 04, 2006 10:07 am
Posts: 9
This is very strange, if i change from List to Set i only get 1 object back. Has nobody experianced anything like this working with inheritance?

_________________
Epllcr


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 9:16 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

I think java.io.Serializable is the answer to your question (your classes should implement it).

It's not so strange that is returning one object (List allow duplicates, while Set not ;) ).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 9:25 am 
Newbie

Joined: Sat Mar 04, 2006 10:07 am
Posts: 9
Thnaks for the answer, all classes implements java.io.Serializable through the AbstractEntity class, so no luck there.

_________________
Epllcr


Top
 Profile  
 
 Post subject: Same problem
PostPosted: Fri Mar 31, 2006 2:39 am 
Newbie

Joined: Fri Apr 29, 2005 11:55 pm
Posts: 14
Location: China-Australia
I have exactly same problem at epllcr, can someone help? I don't want to use a Set, I have to use a List


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.