-->
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: Match all items in a collection
PostPosted: Wed Dec 05, 2007 6:00 am 
Newbie

Joined: Mon Jun 27, 2005 11:49 am
Posts: 7
Location: Norwich, UK
Hi,

I've got a many to many structure between a person and relationship as follows:

Code:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "PARTY_ROLE_TYPE_ID", discriminatorType = DiscriminatorType.STRING)
public abstract class Person {
    /** The unique ID for the entity */
    @Id
    @GeneratedValue
    private Long id;

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
            fetch = FetchType.EAGER)
    @JoinTable(name = "PERSON_RELATIONSHIPS",
            joinColumns = @JoinColumn(name = "PERSON_ID"),
            inverseJoinColumns = @JoinColumn(name = "RELATIONSHIP_ID"))
    private Set<Relationship> relationships;

   ....
}

@Entity
@Table(name = "RELATIONSHIPS")
public class Relationship {
    /* The unique identifier for a relationship */
    @Id
    @GeneratedValue
    @Column(name = "RELATIONSHIP_ID")
    private Long id;

    @Column(name = "TYPE")
    private String type;

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},
            mappedBy = "relationships")
    private Set<Person> parties;

   ...
}


I need to create a query that returns all relationships that contain all given people - this is a query which I run before creating a new relationship to prevent creating relationship duplicates.

I have both Hibernate in Action and Java Persistence with Hibernate but haven't managed to find a section where this type of query is covered.

I have tried creating multiple joins to the collection as you might do in SQL as follows:

Code:
session.createQuery("select r from Relationship r join r.people p where p = ? join r.people p2 where p2.id = ?");

but this fails to parse.

I'm fairly new to hibernate so I'm guessing that I've missed something however looking in the books and Google searches hasn't helped yet.

For reference I'm using: Jboss 4.2.1 with the bundled Hibernate 3.2.4 and Java 5. Our test database is Hypersonic but will move to Oracle 10 when development is complete.

Many thanks.

Stephen


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.