JavaPersistenceWithHibernate读书笔记(4)

1.2.4 Problems relating to associations
    在我们的E-Co实例中的Domain model里,实例对象的关系是用associations表示的,这样User Address和BillingDetials就可以关联起来.不过,BillingDetails与Address不同的是,在BD中这个类有自己表存放数据.
    
    实例对象间的关联及其管理是ORM中的核心内容.
    
    OO中,关联关系是以对象间的引用来表达的,而在SQL世界里,数据的关联是用外键和键值的复制来表示的.关联关系的这两种表示有很大的不同:
    
    Java World:对象间的引用有天生的方向性.
    SQL World: 而靠外键方式获得的关联却没有任何的方向性.
    
     The challenge is to bridge a completely open data model, which is independent of the application that works with the data, to an application-dependent navigational model, a constrained view of the associations needed by this particular application.
 
    在Java里,我们也不能从单向关联里看出任何与关联的数量相关的信息,Java里也可以很轻易地表达出多对多的关联关系.
    而在SQL世界里,表间的关联关系总是一对多或一对一的,这样的数量信息我们也可以很容易的从外键的定义上看的出来.
    
    The following is a foreign key declaration on the BILLING_DETAILS table for a one-to-many association (or, if read in the other direction, a many-to-one association): (现在对这个"一"的理解还是不够,也分不清哪个是"一"哪个是"多" )
    
        USER_ID bigint foreign key references USERS

    These are one-to-one associations:
        USER_ID bigint unique foreign key references USERS
        BILLING_DETAILS_ID bigint primary key foreign key references USERS
        
    而对于多对多的关联关系,我们只能通过一个中间表来表达了.

    We discuss association and collection mappings in great detail in chapters 6 and 7.
    
    So far, the issues we’ve considered are mainly  structural. We can see them by considering a purely static view of the system. Perhaps the most difficult problem in object persistence is a  dynamic problem. It concerns associations, and we’ve already hinted at it when we drew a distinction between object network navigation and table joins in section 1.1.4, “Persistence in object-oriented applications.” Let’s explore this significant mismatch problem in more depth.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值