I have a Book model and Inventory model mapped by ISBN number, but ISBN is not the primary key in either. Each table has its own surrogate primary key - the id column. Books belong to Bookstores and Inventory is for a group of Bookstores(BookstoreChain). Inventory is shared by all Bookstores belonging to a BookstoreChain.
I'm using Hibernate @OneToOne mapping on the book side to fetch inventory info by joining the ISBN column. Somehow, Hibernate generates the left outer join query correctly, but inventory is null on the Book object. Ignoring the Bookstore and Chain, how do i do a OneToOne or ManyToOne join and fetch inventory when Books are fetched?
Code:
class Book{
@Id
Long id
@Column
String isbn;
@Column
String title;
@OneToOne(optional = true)
@JoinColumn(name = "ISBN", referencedColumnName = "ISBN",insertable = false, updatable = false)
Inventory inventory;
}
class Inventory{
@Column
String chainId
@Column
String isbn
@Column
Long availableQty
}