Version 2

    This information is highly time sensitive, it is valid as of 20120724.

     

    Association represents the navigational information to go from an entity A1 to a (list of) entities B1..n. AssociationKey uniquely identify this association information.

    Association is conceptually a Map<RowKey,Tuple> where each Tuple represents the association between A1 and Bi. RowKey is a unique identifier of the A1->Bi association information.

     

    Here are a set of examples of the mapping information and its relation in the internal model of Hibernate OGM

     

     

    // Many to many association
    
    @Entity
    class User {
        @Id String id;
        @ManyToMany
        Set<Address> addresses;
    }
    
    @Entity
    class Address {
        @Id Integer id;
    }
    
    =>
    
    AssociationKey( table=User_Address, columnNames={"user_id", columnValue="emmanuel"})
    Association (selectableColumns={"user_id", "addresses_id"})
        - RowKey(table=User_Address, columnNames={"user_id", "addresses_id"}, columnValues={"Emmanuel", 1})
          Tuple(columnNames={"user_id", "addresses_id"}, columnValues={"Emmanuel", 1})
        - RowKey(table=User_Address, columnNames={"user_id", "addresses_id"}, columnValues={"Emmanuel", 2})
          Tuple(columnNames={"user_id", "addresses_id"}, columnValues={"Emmanuel", 2})
    

     

     

     

    // Many to many association
    // List
    
    @Entity
    class User {
        @Id String id;
        @ManyToMany @OrderColumn("priority")
        List<Address> addresses;
    }
    
    @Entity
    class Address {
        @Id Integer id;
    }
    
    
    =>
    
    AssociationKey( table=User_Address, columnNames={"user_id", columnValue="emmanuel"})
    Association (selectableColumns={"user_id", "priority", "addresses_id"})
        - RowKey(table=User_Address, columnNames={"user_id", "priority"}, columnValues={"Emmanuel", 0})
          Tuple(columnNames={"user_id", "priority", "addresses_id"}, columnValues={"Emmanuel", 0, 1})
        - RowKey(table=User_Address, columnNames={"user_id", "priority"}, columnValues={"Emmanuel", 1})
          Tuple(columnNames={"user_id", "priority", "addresses_id"}, columnValues={"Emmanuel", 1, 2})
    

     

     

    // Many to many association
    // Map
    
    @Entity
    class User {
        @Id String id;
        @ManyToMany @MapKeyColumn("nickname")
        Map<String,Address> addressesByNickname;
    }
    
    @Entity
    class Address {
        @Id Integer id;
    }
    
    
    =>
    
    AssociationKey( table=User_Address, columnNames={"user_id", columnValue="emmanuel"})
    Association (selectableColumns={"user_id", "nickname", "addressesByNickname_id"})
        - RowKey(table=User_Address, columnNames={"user_id", "nickname"}, columnValues={"Emmanuel", "home"})
          Tuple(columnNames={"user_id", "nickname", "addressesByNickname_id"}, columnValues={"Emmanuel", "home", 1})
        - RowKey(table=User_Address, columnNames={"user_id", "nickname"}, columnValues={"Emmanuel", "work"})
          Tuple(columnNames={"user_id", "nickname", "addressesByNickname_id"}, columnValues={"Emmanuel", "work", 2})
    
    

     

     

    // collection of embeddable
    // 
    
    @Entity
    class User {
        @Id String id;
        @ElementCollection
        Set<Address> addresses;
    }
    
    @Embeddable
    class Address {
        String street;
        String city;
    }
    
    =>
    
    AssociationKey( table=User_Address, columnNames={"user_id", columnValue="emmanuel"})
    Association (selectableColumns={"user_id", "addresses_street", "addresses_city"})
        - RowKey(table=User_Address, columnNames={"user_id", "addresses_street", "addresses_city"}, columnValues={"Emmanuel", "avenue des Champs Elysees", "Paris"})
          Tuple(columnNames={"user_id", "addresses_street", "addresses_city"}, columnValues={"Emmanuel", "avenue des Champs Elysees", "Paris"})
        - RowKey(table=User_Address, columnNames={"user_id", "addresses_street", "addresses_city"}, columnValues={"Emmanuel", "Peachtree Street", "Atlanta"})
          Tuple(columnNames={"user_id", "addresses_street", "addresses_city"}, columnValues={"Emmanuel", "Peachtree Street", "Atlanta"})
    

     

     

    // collection of embeddable
    // List
    
    @Entity
    class User {
        @Id String id;
        @ElementCollection @OrderColumn("priority")
        List<Address> addresses;
    }
    
    @Embeddable
    class Address {
        String street;
        String city;
    }
    
    =>
    
    AssociationKey( table=User_Address, columnNames={"user_id", columnValue="emmanuel"})
    Association (selectableColumns={"user_id", "priority", "addresses_street", "addresses_city"})
        - RowKey(table=User_Address, columnNames={"user_id", "priority"}, columnValues={"Emmanuel", 0})
          Tuple(columnNames={"user_id", "priority", "addresses_street", "addresses_city"}, columnValues={"Emmanuel", 0, "avenue des Champs Elysees", "Paris"})
        - RowKey(table=User_Address, columnNames={"user_id", "priority"}, columnValues={"Emmanuel", 1})
          Tuple(columnNames={"user_id", "priority", "addresses_street", "addresses_city"}, columnValues={"Emmanuel", 1, "Peachtree Street", "Atlanta"})
    

     

    This represents the logical model, how data is physically stored in the datastore is entirely dependent of the datastore provider and dialect implementation.

    For example the MongoDB provider has three physical representations, while the Infinispan one stores most of these objects directly in its caches.