Is it possible to have foreign key enforced without object-to-object mapping?

前端 未结 4 645
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 07:15

Assuming the following mappings are provided:


  
  

        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 07:54

    As said

    I understand that if I convert but foreign key would not be enforced by the database.

    So my advice is: use both

    public class EntityA {
    
        private Integer idOfB;
    
        private EntityB entityB;
    
        // getter's and setter's
    
    }
    

    And

    
        
        
        
    
    

    Notice when two properties share the same column, you have to put settings about it in just one property. Otherwise, Hibernate will complain some errors. It explains why i define update="false" and insert="false" in entityB property.

    regards,

提交回复
热议问题