[hibernate-dev] Unidirectional @OneToMany @JoinColumn associations

Stephen Fikes sfikes at redhat.com
Wed May 30 16:44:19 EDT 2018


The referenced attributes *are* key attributes .. just a subset of the 
key. So ... odd mapping ... but I don't think it is included in the 
"optional" category for JPA 2.x.

Stephen


On 05/30/2018 03:39 PM, Sanne Grinovero wrote:
> Hi Gail,
>
> I would not consider it a bug to not have documented that we don't
> support some non-mandatory feature.
>
> And it's still optional in JPA 2.2, so I think we're good.
>
> Thanks,
> Sanne
>
>
>
> On 30 May 2018 at 19:45, Gail Badner <gbadner at redhat.com> wrote:
>> Hi Vlad,
>>
>> Thanks for your answer. There are definitely better ways to model this
>> association.
>>
>> WRT the second example, where the referenced columns are a subset of the PK
>> columns -- I understand there are better ways to model this.
>>
>> In particular, since the subset of PK columns needs to be unique (since
>> they are the referenced columns of a @JoinColumn), there is no reason for
>> any other columns to be in the PK.
>>
>> My question is more about what the JPA spec says about whether this should
>> be supported.
>>
>> Regards,
>> Gail
>>
>>
>>
>>
>>
>> On Wed, May 30, 2018 at 12:47 AM, Vlad Mihalcea <mihalcea.vlad at gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> For the OneToMany with @JoinColumn, the user can workaround this
>>> limitation by just using the @ManyToOne on the child side on any column
>>> they want
>>> and turning the unidirectional association into a bidirectional one. I
>>> remember I tested it and it worked just fine.
>>>
>>> For the  OneToMany with @JoinTable, the only workaround would be if they
>>> map the join table as an entity and use the @ManyToOne on the columns they
>>> want
>>> the association to be based on.
>>>
>>> Since unidirectional associations don't perform that well, I'm not sure
>>> whether it's worth adding support for these use cases.
>>>
>>> Vlad
>>>
>>> On Wed, May 30, 2018 at 9:32 AM, Gail Badner <gbadner at redhat.com> wrote:
>>>
>>>> Unidirectional OneToMany associations using @JoinColumn that reference
>>>> columns that are not PK columns is not currently supported.
>>>>
>>>> The JPA 2.1 documentation for @JoinTable says:
>>>>
>>>> "Support for referenced columns that are not primary key columns of the
>>>> referenced table is optional. Applications that use such mappings will not
>>>> be portable."
>>>>
>>>> I don't see anything in the user doc that explicitly states that Hibernate
>>>> does not support this.
>>>>
>>>> Is this considered a bug?
>>>>
>>>> Also, what about a unidirectional OneToMany using a @JoinColumn that
>>>> references some, but not all, of primary key columns? Hibernate does not
>>>> support that either. Should Hibernate support it since they are primary
>>>> key
>>>> columns?
>>>>
>>>> Thanks,
>>>> Gail
>>>> _______________________________________________
>>>> hibernate-dev mailing list
>>>> hibernate-dev at lists.jboss.org
>>>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>>>
>>>
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev



More information about the hibernate-dev mailing list