-->
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: Query on Entity With OneToMany relation by JoinTable mapping
PostPosted: Mon Nov 12, 2007 5:19 am 
Newbie

Joined: Thu Mar 09, 2006 5:48 am
Posts: 10
Code:
@Entity
public class Shelf {

    public int shelfID;
    public List<Book> books;

     @Id
    @GeneratedValue(strategy= GenerationType.AUTO) 
    public int getShelfID() {
            return shelfID;
    }

    public void setShelfID(int _shelfID) {
       shelfID=_shelfID;
    }

@OneToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
@JoinTable(name="SHELF_BOOK",
                  joinColumns={@JoinColumn(name="SHELF_ID")},
                  inverseJoinColumns={@JoinColumn(name="BOOK_ID")})
   public List<book> getBooks() {
         return books;
    }

    public void setBooks(List<Book> _books) {
        books=_books;
    }

}


Code:
@Entity
public class Book {
    public int bookID;

    @Id
    @GeneratedValue(strategy= GenerationType.AUTO) 
    public int getBookID() {
         return bookID;
    }

    public void setBookID(int _bookID) {
       bookID=_bookID;
    }

}


now my question is :
how can I query for a shelf with shelfID=3 and bookID=4.
something like
Quote:
select s from Shelf s where s.books.id=4 and s.id=3


[/quote]


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.