I posted this question on JBoss EJB3.0 forum but there was no answer. So I am posting it here. I am using Hibernate as a persistence framework.
I have a class Listing with two collections reviews and discussions. Both Review and Discussion are subclasses mapped to the same table, distinguished by a discriminator column type. I am using Seam 1.2.1 but the problem is most likely related to the persistence mapping. Here are the mappings:
Code:
@Entity
@Name("listing")
public class Listing implements java.io.Serializable {
...
@OneToMany(targetEntity = Review.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappe
dBy = "listing")
private Set<Review> reviews = new HashSet<Review>(0);
@OneToMany(targetEntity = Discussion.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, m
appedBy = "listing")
private Set<Discussion> discussions = new HashSet<Discussion>(0);
}
and
Code:
@Entity
@Name("review")
@DiscriminatorValue("review")
@Indexed(index="review")
public class Review extends com.n2.bo.UserContent implements java.io.Serializable {
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "listingId")
private Listing listing;
}
@Entity
@Name("discussion")
@DiscriminatorValue("discussion")
@Indexed(index="discussion")
public class Discussion extends com.n2.bo.UserContent implements java.io.Serializable {
...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "listingId")
private Listing listing;
}
@Entity
@Table(name = "user_content")
@Name("userContent")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type",
discriminatorType = DiscriminatorType.STRING)
public class UserContent implements java.io.Serializable {
...
}
The problem I have is that we I load either reviews or discussions of a listing, both reviews and discussions are loaded into one collection, without checking for discriminator value. I verified this with sql statement there was no where type='review' or where type='discussion' clause. Any idea why?
Thanks.[/code]