I asked this simple question a while ago but got no answer ---
I have table A which contains column c, column c is a foreign key (FK) referring to Table B. I only need to operate on table A. In this case, do I have to specify the foreign key relationship (1-to-1, 1-to-many, etc) in the hibernate mapping xml file ??
I don't think that Hibernate would complain if you don't map this relationship. The database will enforce referential integrity, and Hibernate will just transmit to the application any exception messages from the database.
Joined: Jun 30, 2006
Originally posted by Edvins Reisons: I don't think that Hibernate would complain if you don't map this relationship. The database will enforce referential integrity, and Hibernate will just transmit to the application any exception messages from the database.
Thanks. Let me make sure I understand well --- So you mean I do not need to specify the relationship in hbm.xml file AND the POJO, is that right ? Actually I only have a FK referencing relation but there is not any cascade constraint between the two tables. So, is it OK for me to completely ignore the relationship when I create the hbm.xml config and POJO classes (2 POJO) ?
Joined: Dec 11, 2006
As I understand it, there is no obligation to map relationships for Hibernate. For the foreign key, the database is going to enforce that the values that you set in the foreign key column are present in the referenced column. ORM, including Hibernate, contains mappings that can be used to deal with this, but it's up to you to do otherwise, for example, check this in your application logic.