ManyToMany with aditional fields

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

ManyToMany with aditional fields

John Arevalo
Hi All,

this is my E-R model:

Item
-----------
item_id
item_description
item_price

Order
----------
order_id
order_date
order_customer

Item_order
-------------
item_id
order_id
quantity

i've created an ItemOrderPK with item_id and order_id fields [1] and ItemOrder Entity [2]. When i try to deploy on Glassfish: this exception is thrown:

Exception Description: Entity [class package.ItemOrder] uses [class package.ItemOrderPK] as embedded id class whose access-type has been determined as [FIELD]. But [class package.ItemOrderPK] does not define any [FIELD]. It is likely that you have not provided sufficient metadata in your id class [class package.ItemOrderPK].

How can I solve this exception? or , there is another way to represent this model?

Thanks for your replies.

[1] http://pastebin.com/d1b1a3e6f
[2] http://pastebin.com/m31b4dce7
--
John Arévalo
GNU/Linux User #443701
http://counter.li.org/

_______________________________________________
eclipselink-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany with aditional fields

christopher delahunt
Hello,

Its odd because the exception is stating your ItemOrderPK doesn't have
any fields.  How have you defined the ItemOrderPK class and the item_id
and order_id fields?  Can you post the ItemOrderPK class and how item_id
and order_id fields are mapped?

Best Regards,
Chris

John Arevalo wrote:

> Hi All,
>
> this is my E-R model:
>
> Item
> -----------
> item_id
> item_description
> item_price
>
> Order
> ----------
> order_id
> order_date
> order_customer
>
> Item_order
> -------------
> item_id
> order_id
> quantity
>
> i've created an ItemOrderPK with item_id and order_id fields [1] and
> ItemOrder Entity [2]. When i try to deploy on Glassfish: this
> exception is thrown:
>
> Exception Description: Entity [class package.ItemOrder] uses [class
> package.ItemOrderPK] as embedded id class whose access-type has been
> determined as [FIELD]. But [class package.ItemOrderPK] does not define
> any [FIELD]. It is likely that you have not provided sufficient
> metadata in your id class [class package.ItemOrderPK].
>
> How can I solve this exception? or , there is another way to represent
> this model?
>
> Thanks for your replies.
>
> [1] http://pastebin.com/d1b1a3e6f
> [2] http://pastebin.com/m31b4dce7
> --
> John Arévalo
> GNU/Linux User #443701
> http://counter.li.org/
> ------------------------------------------------------------------------
>
> _______________________________________________
> eclipselink-users mailing list
> [hidden email]
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>  
_______________________________________________
eclipselink-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany with aditional fields

John Arevalo
Hi, thank you for your quick reply.

ItemOrderPK is posted in 1st pastebin link. Full JoinColumn Annotation is:
@JoinColumn(name="item_id",referencedColumnName="item_id")
@ManyToOne
private Item item;

--
John Arévalo
GNU/Linux User #443701
http://counter.li.org/
_______________________________________________
eclipselink-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany with aditional fields

christopher delahunt
Sorry, didn't realize the links where to your classes and not to a
signature.

It looks  like you put the relationships in your PKClass and just used
basic types in your ItemOrder class, which is backwards.
The specification does not allow primary key classes to contain
relationships - they can only contain basic types.

Because you are using an embeddable, you do not need to map anything
other than the quantity in your ItemOrder, and just use itemOrder.id.orderId
to get at the integer values.  If you want to have the relationships,
you can add Order and Item ManyToOne mappings to the ItemOrder but be
sure to mark the columns as insertable=false updatable=false so
that you only have one writable mapping to the column.  If you are using
the latest EclipseLink which implements the @MappedById, you can instead
use it to point to the corresponding id mapping in the embeddable
(avoiding having to define the join column name and mark it as
insertable=false updatable=false).

Best Regards,
Chris


John Arevalo wrote:

> Hi, thank you for your quick reply.
>
> ItemOrderPK is posted in 1st pastebin link. Full JoinColumn Annotation is:
> @JoinColumn(name="item_id",referencedColumnName="item_id")
> @ManyToOne
> private Item item;
>
> --
> John Arévalo
> GNU/Linux User #443701
> http://counter.li.org/
> _______________________________________________
> eclipselink-users mailing list
> [hidden email]
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>  
_______________________________________________
eclipselink-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: ManyToMany with aditional fields

John Arevalo
On Thu, Jul 9, 2009 at 4:25 PM, christopher
delahunt<[hidden email]> wrote:

> Sorry, didn't realize the links where to your classes and not to a
> signature.
> It looks  like you put the relationships in your PKClass and just used basic
> types in your ItemOrder class, which is backwards.
> The specification does not allow primary key classes to contain
> relationships - they can only contain basic types.
> Because you are using an embeddable, you do not need to map anything other
> than the quantity in your ItemOrder, and just use itemOrder.id.orderId
> to get at the integer values.  If you want to have the relationships, you
> can add Order and Item ManyToOne mappings to the ItemOrder but be sure to
> mark the columns as insertable=false updatable=false so
> that you only have one writable mapping to the column.  If you are using the
> latest EclipseLink which implements the @MappedById, you can instead use it
> to point to the corresponding id mapping in the embeddable
> (avoiding having to define the join column name and mark it as
> insertable=false updatable=false).
> Best Regards,
> Chris
>
>
> John Arevalo wrote:
>>
>> Hi, thank you for your quick reply.
>>
>> ItemOrderPK is posted in 1st pastebin link. Full JoinColumn Annotation is:
>> @JoinColumn(name="item_id",referencedColumnName="item_id")
>> @ManyToOne
>> private Item item;
>>
>> --
>> John Arévalo
>> GNU/Linux User #443701
>> http://counter.li.org/
>> _______________________________________________
>> eclipselink-users mailing list
>> [hidden email]
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
>
> _______________________________________________
> eclipselink-users mailing list
> [hidden email]
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>

Thanks Christopher, it worked perfectly adding non-updatable JoinColumn.

MappedId won't be portable to another JPA implementation, doesn't it?

--
John Arévalo
GNU/Linux User #443701
http://counter.li.org/
_______________________________________________
eclipselink-users mailing list
[hidden email]
https://dev.eclipse.org/mailman/listinfo/eclipselink-users