dev@glassfish.java.net

Re: Mapping one colunm in two foreign keys

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Fri, 19 Dec 2008 15:33:41 -0400

I apologize I should have looked at your mapping more closely. In
TopLink's JPA support what you are attempting to do is not supported. I
assume that you have constructed your mappings this way because you may
not always have a "Bairro" set? If you do you could just make this
mapping writable and all other not writable.

Alternatively you could use a Descriptor Customizer. (Check the
glassfish forums there are numerous examples) to create the mappings and
use the mapping.addTargetForeignKeyField(DatabaseField, DatabaseField)
for those columns that you have marked as read only.

A great source of documentation for TopLink Essentials can be found at
http://www.oracle.com/technology/products/ias/toplink/doc/index.html .
Although this is Oracle TopLink documentation the vast majority of the
functionality is the same.
--Gordon

Guilherme Namen Pimenta wrote:
> If i remove the "insertable = false, updatable = false" toplink will
> not incialize because one column will be in two JoinColumn
> Exemple:
>
> @JoinColumn(name = "CDPAIS", referencedColumnName = "CDPAIS")
> @ManyToOne(fetch = FetchType.LAZY)
> private Pais pais;
>
> @JoinColumns({ @JoinColumn(name = "CDPAIS", referencedColumnName =
> "CDPAIS", insertable = false, updatable = false),
> @JoinColumn(name = "SGESTADO", referencedColumnName =
> "SGESTADO")})
> @ManyToOne(fetch = FetchType.LAZY)
> private Estado estado;
>
> The column CDPAIS is in two foreign keys on for mapping Pais, and
> another for mapping Estado whit SGESTADO.
> So the data for column CDPAIS came from entity Pais, and the value for
> column SGESTADO cames from Estado entity.
>
>
> Em Fri, 19 Dec 2008 09:59:34 -0300, Gordon Yorke
> <gordon.yorke_at_oracle.com> escreveu:
>
>> This is because you have marked the columns as not updatable and not
>> insertable. (insertable = false, updatable = false) TopLink will not
>> write values to columns you have configured to not be writable, that
>> would violate your configuration and no doubt raise SQL exceptions.
>> These columns must be marked as writable if you wish TopLink to write
>> to them.
>> --Gordon
>>
>> Guilherme Namen Pimenta wrote:
>>> Hello.
>>> Could someone help me to implement mappgin one column in two foreign
>>> keys.
>>> To be more especifc i want to implemet this kind of relationship:
>>>
>>> @JoinColumns({
>>> @JoinColumn(name = "CDPAIS", referencedColumnName = "CDPAIS",
>>> insertable = false, updatable = false),
>>> @JoinColumn(name = "SGESTADO", referencedColumnName =
>>> "SGESTADO",
>>> insertable = false, updatable = false),
>>> @JoinColumn(name = "CDMUNICIPIO", referencedColumnName =
>>> "CDMUNICIPIO", insertable = false, updatable = false),
>>> @JoinColumn(name = "CDBAIRRO", referencedColumnName =
>>> "CDBAIRRO")})
>>> @ManyToOne(fetch = FetchType.LAZY)
>>> private Bairro bairro;
>>>
>>> @JoinColumns({
>>> @JoinColumn(name = "CDPAIS", referencedColumnName = "CDPAIS",
>>> insertable = false, updatable = false),
>>> @JoinColumn(name = "SGESTADO", referencedColumnName =
>>> "SGESTADO")})
>>> @ManyToOne(fetch = FetchType.LAZY)
>>> private Estado estado;
>>>
>>> @JoinColumns({
>>> @JoinColumn(name = "CDPAIS", referencedColumnName = "CDPAIS",
>>> insertable = false, updatable = false),
>>> @JoinColumn(name = "SGESTADO", referencedColumnName =
>>> "SGESTADO",
>>> insertable = false, updatable = false),
>>> @JoinColumn(name = "CDMUNICIPIO", referencedColumnName =
>>> "CDMUNICIPIO")})
>>> @ManyToOne(fetch = FetchType.LAZY)
>>> private Municipio municipio;
>>>
>>> @JoinColumn(name = "CDPAIS", referencedColumnName = "CDPAIS")
>>> @ManyToOne(fetch = FetchType.LAZY)
>>> private Pais pais;
>>>
>>> TopLink can't generete correct insert an update sql setence for this
>>> mapping, it simple ignores the municipio, estado and bairro.
>>> Thanks
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>
>
>
>