posted 10 years ago
Hi All,
While learning the concepts of associations in ORM using Hibernate, i'm trying with an example 1-1 unidirection mapping between two entities.
ClassA
ClassB
Now I persisted tables initially as below
TABLE-A
+-------------+-------------+
| ID | B |
+-------------+-------------+
| 1 | null |
| 2 | null |
+-------------+-------------+
TABLE - B
+-------------+
| ID |
+-------------+
| 123 |
+-------------+
and then trying to map the association, by adding the key "123" as a foreign key to TABLE - A for the first record (PK = 1) and then tried to add "123" as a foreign Key again to another record with PK = 2. Which would effectively yield to Many to One, unidirectional. I used "unique = true" on <many-to-one> side of ClassA mapping file, with the hope that, Hibernate would enfore One - One. But it seems, it ignored it and still letting me map Many classA to one ClassB.
Is there anything wrong, I'm doing here. How do I enforce one - one mapping.