Well, I am new to Hibernate and the question I have is quite trivial. I found few answers explaining it but may be I am not getting it exactly and I am still stuck.
I found that to map a foreign key I need to map an entity, like below
// this is GroupEntity
// mapping bond_id from Bond table
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name ="bond_id")
private BondEntity bondEntity;
I believe this maps bond_id column from BondEntity's table to bond_id of present table.
Now how do I set this bond_id to DB while persisting the entity of this table. Unlike other columns this field now takes an object.
I tried setting only the bond_id, like
BondEntity bondEntity = new BondEntity();
bondEntity.setBondId(1234); //remaining field of bondEntity not set
groupEntity.setBondEntity(bondEntity);
If I go ahead and try persisting this entity, I get detached entity passed to persist in hibernate
.
Whats the correct way of doing it. May be I am not getting it correctly.