-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem with loading the collections
PostPosted: Mon Jun 25, 2007 10:14 am 
Newbie

Joined: Mon May 07, 2007 8:37 pm
Posts: 15
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]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 8:36 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The short answer is that it's forbidden.
For the long explanation, check the forum; it has been debated in the past.

I believe some people worked around it by using @Where, but it's not supported. The correct workaround is to have a clean design.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 10:47 am 
Newbie

Joined: Mon May 07, 2007 8:37 pm
Posts: 15
I did find a lot of threads on this issue. The workaround is @Where("discriminator-column='discriminator-value'") annotation. But it seems that since there is such a big need for it, it would be nice if Hibernate implements it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 11:26 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No if people want to shoot themselves in the foot, I'm not going to help them.

_________________
Emmanuel


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