users@glassfish.java.net

JPA AdvancedMapping sample

From: <glassfish_at_javadesktop.org>
Date: Wed, 20 Oct 2010 15:57:54 PDT

Hi everybody,
I was looking to the jpa advancedmapping sample which is shipped with GlassFish Enterprise Server.
I don't know if there's someone who took a look at it. I found something that is rather wierd. What the lineItemNumber attribute in the LineItem class, is for ?
Looking at the EJB code doesn't help very much, it just seems that it's used as the item identifier, but is not mapped that way.
In the database side, this attribute is mapped with the LINEITEMNUMBER of the LINEITEM table. This column is a part of a composed primary key (with the order_id column), and no foreign key is defined on it. I could insert a record with order_id=1,lineitems_key=1 and lineitemnumber=15. The result of the client execution gives (Notice that the first order is retrieved twice):

Executing query...select o from Order o join o.lineItems li where KEY(li).name = ?1
Retrieved Order id is: 2
Retrieved Order id is: 3
Retrieved Order id is: 4
Retrieved Order id is: 1
Retrieved Order id is: 1

Then :

Executing query...select ENTRY(li) from Order o join o.lineItems li where o.id = ?1
        LineIten: 2 Item: ItemName2 Qty Ordered: 2
        LineIten: 1 Item: ItemName1 Qty Ordered: 1
        LineIten: 3 Item: ItemName3 Qty Ordered: 3
        LineIten: 15 Item: ItemName1 Qty Ordered: 20

The itemName1 is retrieved twice which is rather inconsistent, as the item is the key of the lineItems map.

Am I missing something, or the lineItemNumber must be defined (and mapped) as the item identifier ?

Thanks in advance for your replies.
[Message sent by forum member 'hamdi_douss']

http://forums.java.net/jive/thread.jspa?messageID=485777