Page 1 of 1

About Question enthuware.oce-jpad.v6.2.415 :

Posted: Sun Jun 25, 2017 6:32 pm
by himaiMinh
Hi, everyone,
In the explanation,
When the key or value is an entity, AssociationOverride is used.
I think AssociationOverride is used when the value is an entity. I don't think we will use associationoverride to override the key.
Here is what the spec says:
The AttributeOverride(s) and AssociationOverride(s) annotations are
used to override the mappings for a map value that is an embeddable class.

Re: About Question enthuware.oce-jpad.v6.2.415 :

Posted: Tue Jun 27, 2017 10:12 pm
by admin
This quote is only talking about the case when the value is an embedded class. What if the key or the value is an entity?

Re: About Question enthuware.oce-jpad.v6.2.415 :

Posted: Mon Jul 03, 2017 1:15 pm
by himaiMinh
If the key is an entity, we use @MapKeyJoinColumn to indicate there is a column with the primary key of this entity.
If the value is an entity, we use the primary key of the entity in the join table.

Re: About Question enthuware.oce-jpad.v6.2.415 :

Posted: Mon Sep 17, 2018 1:25 pm
by __JJ__
himaiMinh wrote:
Mon Jul 03, 2017 1:15 pm
If the key is an entity, we use @MapKeyJoinColumn to indicate there is a column with the primary key of this entity.
If the key is an entity, we use @MapKeyJoinColumn to override the default name of the column in the db that will hold the FK back to the entity's PK.

Code: Select all

    @ElementCollection
    @CollectionTable(name = "EMP_ROLE")
    @MapKeyJoinColumn(name = "EMP_ID") <== override default FK column name; but not really necessary
    @Column(name = "ROLE")
    private Map<Employee, String> employeeRole;