hibernatejpaormeclipselinkopenjpa

What is referencedColumnName used for in JPA?


In JPA there is an attribute called referencedColumnName that can be set on @JoinColumn, @PrimaryKeyJoinColumn what is the idea behind this setting, can someone give a good example of where this can be used?


Solution

  • It is there to specify another column as the default id column of the other table, e.g. consider the following

    TableA
      id int identity
      tableb_key varchar
    
    
    TableB
      id int identity
      key varchar unique
    
    // usage in class for TableA
    @JoinColumn(name="tableb_key", referencedColumnName="key")