File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Two classes with an association between them" mapping? Need help..

 
Grigory BLAH. Ptashko
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I'm new to Hibernate and all that Object/Relational mapping stuff. I need a recipe in Hibernate of the simplest relational situation.
Let me explain.

I have three tables



As you see the first two are simple entities and the third one shows which DVD a specific user has taken.
In my application I have to be able to know these things:


1) What user has which DVDs.
SQL query would be:



2) Which DVDs are vacant (not taken by other users).
SQL query would be:


Users also have to be able to take and give back DVDs. It means to insert into/delete from the TakenItem table.

So, I made up a hibernate-mapping for two classes Users and DVD in a standard and simple with one id and some fields (as any of the tutorials say).
But the problem is that I don't understand what to do with the third table and what hibernate-mapping must I write to be able to make queries that I described before?

I appreciate any advices.

Thank you.
 
Chris Richardson
author
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Grigory,

I think you want a (possibly bidirectional) many-to-many relationship between users and dvds. See http://www.hibernate.org/hib_docs/v3/reference/en/html/associations.html#assoc-bidirectional-join-m2m for an example.

In your particular example TakenItems is the join table (PersonAddress in the Hibernate example)

Chris
 
Grigory BLAH. Ptashko
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
That is exactly what I need!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic