[hibernate-dev] Use @AssociationOverride with @MapKeyJoinColumn

Florian Lacreuse florian.lacreuse at smile.fr
Wed Nov 23 11:09:37 EST 2016


We didn't know about the JPA spec on this particular detail, thanks for 
the precision.

Nonetheless, we don't want to override the @MapKeyJoinColumn, we just 
want the annotation to be taken into consideration while we use 
@AssociationOverride to override something else.

We have updated the test case 
(https://github.com/florianlacreuse/hibernate-test-case 
<https://github.com/florianlacreuse/hibernate-test-case>). In Employee 
entity we use the same embeddable twice, so we have to use
@AssociationOverride to name the two join tables. In both tables, the 
column related to the key has the default name ("experiences_KEY") 
instead of the one provided by the @MapKeyJoinColumn ("jobtitle_id").

To resume, we understrand that it's not possible to override 
@MapKeyJoinColumn but @MapKeyJoinColumn should not be ignored.

In Employee entity you can also find a third attribute with the same 
embeddable but without any @AssociationOverride. In this case, 
@MapKeyJoinColumn works as expected.

Kind regards,

Logo <http://www.smile.fr/>

151 boulevard Stalingrad
69100 Villeurbanne
www.smile.fr <http://www.smile.fr/> 	
*Florian LACREUSE*
Ingénieur d'études et développement
Pôle Développement Spécifique Java
Open Wide - Systèmes d'Information
Email : florian.lacreuse at smile.fr <mailto:florian.lacreuse at smile.fr>


Le 23/11/2016 à 16:08, Vlad Mihalcea a écrit :
> The JPA spec does not specify a way to override the MapKeyJoinColumn. 
> You can override the association, like the JoinColumn for a ManyToOne 
> or a JoinTable for OneToMany.
>
> In your case, maybe it's better to move that association out of the 
> embeddable.
> It's always a good idea to keep the model as simple as possible.
>
> Vlad
>
> On Wed, Nov 23, 2016 at 4:10 PM, Florian Lacreuse 
> <florian.lacreuse at smile.fr <mailto:florian.lacreuse at smile.fr>> wrote:
>
>     Hi,
>
>     We have a problem using @AssociationOverride and @MapKeyJoinColumn and
>     we would like to have your opinion about this to know if this is
>     an issue.
>
>     Here is the test case :
>     https://github.com/florianlacreuse/hibernate-test-case
>     <https://github.com/florianlacreuse/hibernate-test-case>
>
>     Short explanation about the model : an entity with an embeddable field
>     wrapping a map with an entity as key and a basic type as value.
>
>     We use @AssociationOverride to rename the join table (annotation on
>     embeddable field) and @MapKeyJoinColumn to rename the column
>     related to
>     the key map (annotation on map field).
>
>     Unfortunately, it would seem that the @MapKeyJoinColumn annotation is
>     ignored. @AssociationOverride may override any other annotations
>     on the
>     map field ? In this case how to rename the column related to the
>     key map
>     with the @AssociationOverride ?
>
>     Is this an issue or is there any trick we don't know about?
>
>     Thanks for your help.
>
>     Kind regards,
>
>
>     Logo <http://www.smile.fr/>
>
>     151 boulevard Stalingrad
>     69100 Villeurbanne
>     www.smile.fr <http://www.smile.fr> <http://www.smile.fr/>
>     *Florian LACREUSE*
>     Ingénieur d'études et développement
>     Pôle Développement Spécifique Java
>     Open Wide - Systèmes d'Information
>     Email : florian.lacreuse at smile.fr
>     <mailto:florian.lacreuse at smile.fr>
>     <mailto:florian.lacreuse at smile.fr <mailto:florian.lacreuse at smile.fr>>
>
>
>     _______________________________________________
>     hibernate-dev mailing list
>     hibernate-dev at lists.jboss.org <mailto:hibernate-dev at lists.jboss.org>
>     https://lists.jboss.org/mailman/listinfo/hibernate-dev
>     <https://lists.jboss.org/mailman/listinfo/hibernate-dev>
>
>



More information about the hibernate-dev mailing list