There are two tables TableA and TableB.
TableA id (pk), col_A1, col_A2 -------------------------------------------- 1, 1000, col_a_val1 2, 1001, col_a_val2
TableB id (pk), col_B (unique) ----------------------- 1000, col_b_val1 1001, col_b_val2 ## TableA.col_A1 references TableB.id
public class TableAObj { private String id; private String colA1; private String colA2; }
TableAObj is populated with the below values - id = 1 - colA1 = col_b_val1; - colA2 = col_a_val1
When TableAObj is persisted it should stamp the pk corresponding to “col_b_val1” (1000) in col_A1 of TableA. Also when TableAObj is loaded from database colA1 field should contain "col_b_val1" instead of 1000.
How to achieve this using hibernate mapping?
|