2

I am using Spring data JPA(Hibernate). I am trying to join my tables (Table A & Table B) but on Non-Primary Columns. Is it possible to actually do that? I am trying to use referenceColumnName, but it seems to not working, giving error :

Cannot set int to Integer. When I am removing referenceColumnName, then it is working but obviously it is joining with Primary Key. Also in case of One-to-one Bidirectional, where should I place mappedBy & JoinColumn?

Ankit Bansal
  • 2,162
  • 8
  • 42
  • 79

1 Answers1

0

The annotation @JoinColumn indicates that this entity is the owner of the relationship (that is: the corresponding table has a column with a foreign key to the referenced table), whereas the attribute mappedBy indicates that the entity in this side is the inverse of the relationship, and the owner resides in the "other" entity.
Regarding the other question of using joining tables on Non-Primary columns, there are plenty of threads why don't you go through. for example Does the JPA specification allow references to non-primary key columns?

Community
  • 1
  • 1
pvpkiran
  • 25,582
  • 8
  • 87
  • 134
  • I have read many blogs which suggests mappedBy is in the side of owner of relationship(in case of OnetoMany). Is it different for type of association meaning different for OneToOne & OneToMany? – Ankit Bansal Apr 24 '17 at 08:02