[jboss-user] [EJB 3.0] - weird problem with loading collections of subclasses
tuxzilla
do-not-reply at jboss.com
Sat Jun 23 14:51:49 EDT 2007
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:
| @Entity
| @Name("listing")
| public class Listing implements java.io.Serializable {
| ...
|
| @OneToMany(targetEntity = Review.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "listing")
| private Set<Review> reviews = new HashSet<Review>(0);
|
| @OneToMany(targetEntity = Discussion.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "listing")
| private Set<Discussion> discussions = new HashSet<Discussion>(0);
|
| }
|
|
and
| @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.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4057147#4057147
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4057147
More information about the jboss-user
mailing list