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.