-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria queries with many-to-many joins
PostPosted: Fri Mar 28, 2008 1:24 pm 
Newbie

Joined: Fri Mar 28, 2008 1:12 pm
Posts: 1
Hello,

I'm having a hard time figuring out the correct way to configure a criteria query and I'm hoping someone can help me out or point in the right direction.

The annotated classes are below, but basically I have two entities: Account and ChartReview. A ChartReview has many reviewers (accounts) and an Account can have many ChartReviews. I'm trying to figure out how to define a criteria query that returns all ChartReviews where Account X is one of the reviewers. It has to be a criteria query because I'll be sorting the results by different Account properties at runtime.

Thanks for you help!

Hibernate version:
3.2

Mapping documents:
Code:

@Entity
@Table(name="accounts"
public class Account {
  @ManyToMany
    @JoinTable(
        name="chart_reviewers",
        joinColumns=
            @JoinColumn(name="account_id"),
        inverseJoinColumns=
            @JoinColumn(name="chart_review_id")
    )
  private List<ChartReview> chartReviews;

  // Other mapped properties like id, etc
}

@Entity
@Table(name="chart_reviews")
public class ChartReview {

  @ManyToMany
    @JoinTable(
        name="chart_reviewers",
        joinColumns=
            @JoinColumn(name="chart_review_id"),
        inverseJoinColumns=
            @JoinColumn(name="account_id")
    )
  private List<Account> reviewers;

  // Other mapped properties like id, etc
}



Name and version of the database you are using:
Oracle 10gR2


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.