Using several collection mapping of the same type

View: New views
5 Messages — Rating Filter:   Alert me  

Using several collection mapping of the same type

by Pierre-Yves SAUMONT-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I could not find information about the following case: An entity as
several properties that are collection of another same entity.

For example, a Client entity has a collection of Order called
executedOrderList and a second called pendingOrderList.

This is declared in Client as :

@OneToMany(cascade = CascadeType.ALL)
List<Order> executedOrderList;

@OneToMany(cascade = CascadeType.ALL)
Lsit<Order> pendingOrderList;

This results is an table called CLIENT_ORDER with three columns:

CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID, PENDINGORDERLIST_UNIQUEID

with a composite primary key:

PRIMARY KEY CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID,
PENDINGORDERLIST_UNIQUEID

so far, so good.

The problem is that all three columns in that table must be non null and
have no default value which result in an error as soon as one entry is
added since it automatically have one of the two last column null.

I can workaround this by editing the create.sql generated file and
either adding DEFULT "" or removing NOT NULL.

My question is how can I make eclipselink generate this correctly, so
that I do not need to edit the generated SQL manually ?

Pierre-Yves
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Using several collection mapping of the same type

by christopher delahunt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

They should not be using the same relation table.  You need to define
atleast one of the OntToMany mappings to use different table using the
JoinTable annotation or you will get into problems when it tries to
remove from the table as well.

Best Regards,
Chris

Pierre-Yves SAUMONT wrote:

> Hi,
>
> I could not find information about the following case: An entity as
> several properties that are collection of another same entity.
>
> For example, a Client entity has a collection of Order called
> executedOrderList and a second called pendingOrderList.
>
> This is declared in Client as :
>
> @OneToMany(cascade = CascadeType.ALL)
> List<Order> executedOrderList;
>
> @OneToMany(cascade = CascadeType.ALL)
> Lsit<Order> pendingOrderList;
>
> This results is an table called CLIENT_ORDER with three columns:
>
> CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID, PENDINGORDERLIST_UNIQUEID
>
> with a composite primary key:
>
> PRIMARY KEY CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID,
> PENDINGORDERLIST_UNIQUEID
>
> so far, so good.
>
> The problem is that all three columns in that table must be non null
> and have no default value which result in an error as soon as one
> entry is added since it automatically have one of the two last column
> null.
>
> I can workaround this by editing the create.sql generated file and
> either adding DEFULT "" or removing NOT NULL.
>
> My question is how can I make eclipselink generate this correctly, so
> that I do not need to edit the generated SQL manually ?
>
> Pierre-Yves
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Using several collection mapping of the same type

by Pierre-Yves SAUMONT-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Chris,

Thanks for the info. It's difficult to understand why Eclipselink does
this (create a multicolumn join table) if it can't work!
While testing it (after modifying the table to have a default value of
""), the result is that deleting works fine except for the last item in
the table (whatever the order of creation).

Beside using separate tables (which I am going to try asap), could you
please elaborate on the reason why removing is causing problems ?

Thanks,

Pierre-Yves


christopher delahunt wrote:

> Hello,
>
> They should not be using the same relation table.  You need to define
> atleast one of the OntToMany mappings to use different table using the
> JoinTable annotation or you will get into problems when it tries to
> remove from the table as well.
>
> Best Regards,
> Chris
>
> Pierre-Yves SAUMONT wrote:
>> Hi,
>>
>> I could not find information about the following case: An entity as
>> several properties that are collection of another same entity.
>>
>> For example, a Client entity has a collection of Order called
>> executedOrderList and a second called pendingOrderList.
>>
>> This is declared in Client as :
>>
>> @OneToMany(cascade = CascadeType.ALL)
>> List<Order> executedOrderList;
>>
>> @OneToMany(cascade = CascadeType.ALL)
>> Lsit<Order> pendingOrderList;
>>
>> This results is an table called CLIENT_ORDER with three columns:
>>
>> CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID, PENDINGORDERLIST_UNIQUEID
>>
>> with a composite primary key:
>>
>> PRIMARY KEY CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID,
>> PENDINGORDERLIST_UNIQUEID
>>
>> so far, so good.
>>
>> The problem is that all three columns in that table must be non null
>> and have no default value which result in an error as soon as one
>> entry is added since it automatically have one of the two last column
>> null.
>>
>> I can workaround this by editing the create.sql generated file and
>> either adding DEFULT "" or removing NOT NULL.
>>
>> My question is how can I make eclipselink generate this correctly, so
>> that I do not need to edit the generated SQL manually ?
>>
>> Pierre-Yves
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@...
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Using several collection mapping of the same type

by christopher delahunt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Pierre-Yves,

The JPA specification mandated that relation table names default to
CLASSA_CLASSB, causing problems when using defaults and having more than
one collection mapping requiring a relation table (M:M or
uni-directional 1:M mappings).

I don't remember off hand how EclipseLink will remove an entire
collection, but if you null out one collection and not the other, you
might get into problems where the provider might use Delete from
CLIENT_ORDER where (CLIENT_UNIQUEID = x).

Best Regards,
Chris

Pierre-Yves SAUMONT wrote:

> Hello Chris,
>
> Thanks for the info. It's difficult to understand why Eclipselink does
> this (create a multicolumn join table) if it can't work!
> While testing it (after modifying the table to have a default value of
> ""), the result is that deleting works fine except for the last item
> in the table (whatever the order of creation).
>
> Beside using separate tables (which I am going to try asap), could you
> please elaborate on the reason why removing is causing problems ?
>
> Thanks,
>
> Pierre-Yves
>
>
> christopher delahunt wrote:
>> Hello,
>>
>> They should not be using the same relation table.  You need to define
>> atleast one of the OntToMany mappings to use different table using
>> the JoinTable annotation or you will get into problems when it tries
>> to remove from the table as well.
>>
>> Best Regards,
>> Chris
>>
>> Pierre-Yves SAUMONT wrote:
>>> Hi,
>>>
>>> I could not find information about the following case: An entity as
>>> several properties that are collection of another same entity.
>>>
>>> For example, a Client entity has a collection of Order called
>>> executedOrderList and a second called pendingOrderList.
>>>
>>> This is declared in Client as :
>>>
>>> @OneToMany(cascade = CascadeType.ALL)
>>> List<Order> executedOrderList;
>>>
>>> @OneToMany(cascade = CascadeType.ALL)
>>> Lsit<Order> pendingOrderList;
>>>
>>> This results is an table called CLIENT_ORDER with three columns:
>>>
>>> CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID, PENDINGORDERLIST_UNIQUEID
>>>
>>> with a composite primary key:
>>>
>>> PRIMARY KEY CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID,
>>> PENDINGORDERLIST_UNIQUEID
>>>
>>> so far, so good.
>>>
>>> The problem is that all three columns in that table must be non null
>>> and have no default value which result in an error as soon as one
>>> entry is added since it automatically have one of the two last
>>> column null.
>>>
>>> I can workaround this by editing the create.sql generated file and
>>> either adding DEFULT "" or removing NOT NULL.
>>>
>>> My question is how can I make eclipselink generate this correctly,
>>> so that I do not need to edit the generated SQL manually ?
>>>
>>> Pierre-Yves
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@...
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@...
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: Using several collection mapping of the same type

by Pierre-Yves Saumont :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Chris,

My use case is not to null the whole collection, but only to remove elements. This could result in removing all elements corresponding to one property, but it should not cause any problem. By the way, once the tables are modified to include a default value (an empty string), it seems to work fine.

As our code is automatically generated, we need to minimize configuration. Setting a join table explicitly is a problem because the code generator has to figure if other properties of the same type exist in the class, or alternately, it has to specify a join table for all properties.

So my question is: Is the lack of a default value in the generated tables a bug? Or is it something choosen to discourage the use of multicolumn joint tables while conforming to the spec?

Best regards,

Pierre-Yves


Christopher Delahunt wrote:
Hello Pierre-Yves,

The JPA specification mandated that relation table names default to
CLASSA_CLASSB, causing problems when using defaults and having more than
one collection mapping requiring a relation table (M:M or
uni-directional 1:M mappings).

I don't remember off hand how EclipseLink will remove an entire
collection, but if you null out one collection and not the other, you
might get into problems where the provider might use Delete from
CLIENT_ORDER where (CLIENT_UNIQUEID = x).

Best Regards,
Chris

Pierre-Yves SAUMONT wrote:
> Hello Chris,
>
> Thanks for the info. It's difficult to understand why Eclipselink does
> this (create a multicolumn join table) if it can't work!
> While testing it (after modifying the table to have a default value of
> ""), the result is that deleting works fine except for the last item
> in the table (whatever the order of creation).
>
> Beside using separate tables (which I am going to try asap), could you
> please elaborate on the reason why removing is causing problems ?
>
> Thanks,
>
> Pierre-Yves
>
>
> christopher delahunt wrote:
>> Hello,
>>
>> They should not be using the same relation table.  You need to define
>> atleast one of the OntToMany mappings to use different table using
>> the JoinTable annotation or you will get into problems when it tries
>> to remove from the table as well.
>>
>> Best Regards,
>> Chris
>>
>> Pierre-Yves SAUMONT wrote:
>>> Hi,
>>>
>>> I could not find information about the following case: An entity as
>>> several properties that are collection of another same entity.
>>>
>>> For example, a Client entity has a collection of Order called
>>> executedOrderList and a second called pendingOrderList.
>>>
>>> This is declared in Client as :
>>>
>>> @OneToMany(cascade = CascadeType.ALL)
>>> List<Order> executedOrderList;
>>>
>>> @OneToMany(cascade = CascadeType.ALL)
>>> Lsit<Order> pendingOrderList;
>>>
>>> This results is an table called CLIENT_ORDER with three columns:
>>>
>>> CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID, PENDINGORDERLIST_UNIQUEID
>>>
>>> with a composite primary key:
>>>
>>> PRIMARY KEY CLIENT_UNIQUEID, EXECUTEDORDERLIST_UNIQUEID,
>>> PENDINGORDERLIST_UNIQUEID
>>>
>>> so far, so good.
>>>
>>> The problem is that all three columns in that table must be non null
>>> and have no default value which result in an error as soon as one
>>> entry is added since it automatically have one of the two last
>>> column null.
>>>
>>> I can workaround this by editing the create.sql generated file and
>>> either adding DEFULT "" or removing NOT NULL.
>>>
>>> My question is how can I make eclipselink generate this correctly,
>>> so that I do not need to edit the generated SQL manually ?
>>>
>>> Pierre-Yves
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@eclipse.org
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@eclipse.org
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@eclipse.org
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/eclipselink-users