• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OneToOne mapping using join table

 
Laura Pozhilova
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have 3 tables which I have to use to write a one to one mapping I can't use a db structure. The first table's name is ReferenceBook, the second's - ReferenceBookTitle and the join table's name is Binding. I think it's clear that the third table is using for making mappings like one to one and so on. In this case I have to know in ReferenceBook it's title.

ReferenceBook: id and so on,
ReferenceBookTitle: id and so on,
Binding: id, parent_id(which is referenceBookTitle_fk), child_id(referenceBook_fk), number of other columns.

Entities:

ReferenceBook.java


ReferenceBookTitle.java


Binding.java


What should I write in these entities in case to implement a correct mapping?

Please, help me!

Thank you in advance

L.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Book your would have,



And the inverse in the Title.

But, since you have other columns in the table, and have a class defined for Binding, I don't see why you would do this. Instead define a normal OneToOne from Book and Title to Binding, and in Binding define a OneToOne to Book and Title.
 
Laura Pozhilova
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, James!

Thank you for your reply. I did think about the way you talk about - having simple OneToOne from Book to Binding and from Title to Binding. But I'd like to have title property in Book and book property in Title. What's more I don't like having Binding property in these Entities. So maybe the first solution is better, isn't it?

What I don't understand now is how to get Binding's properties...Do you have any ideas?

L.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic