Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334729 - @ElementCollection with @Embeddable using @OrderColumn fails to correctly populate the order field
Summary: @ElementCollection with @Embeddable using @OrderColumn fails to correctly pop...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-18 23:05 EST by Greg Tan CLA
Modified: 2022-06-09 10:34 EDT (History)
2 users (show)

See Also:


Attachments
Test case for OrderColum on ElementCollection of Embeddables failing to populate (2.91 KB, application/octet-stream)
2011-01-18 23:06 EST, Greg Tan CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Tan CLA 2011-01-18 23:05:26 EST
Build Identifier: 2.1.2.v20101206-r8635

I have an Entity with a List of Embeddables which have an @OrderColumn set. When I read the entity, the embeddables all have their order columns set to 0.

This also causes problems when mutating the list of embeddables. As the order column is not set correctly, when deleting old values prior to inserting the new values, the old values cannot be correctly deleted as the where clause references the order column (which is incorrect) and so the delete fails.

When I set eclipselink.cache.shared.default=false, the order columns are correctly populated

I have attached a test case. From the log output:

Inserting the entity, the sequence is correct.

[EL Fine]: 2011-01-19 11:58:17.502--ClientSession(1903736395)--Connection(467120674)--Thread(Thread[main,5,main])--INSERT INTO Ent_EMBEDDABLES (Ent_ID, SEQUENCE, VALUE) VALUES (?, ?, ?)
	bind => [1, 0, A]
[EL Fine]: 2011-01-19 11:58:17.51--ClientSession(1903736395)--Connection(467120674)--Thread(Thread[main,5,main])--INSERT INTO Ent_EMBEDDABLES (Ent_ID, SEQUENCE, VALUE) VALUES (?, ?, ?)
	bind => [1, 1, B]
[EL Fine]: 2011-01-19 11:58:17.511--ClientSession(1903736395)--Connection(467120674)--Thread(Thread[main,5,main])--INSERT INTO Ent_EMBEDDABLES (Ent_ID, SEQUENCE, VALUE) VALUES (?, ?, ?)
	bind => [1, 2, C]

toString() of the Entity, which was obtained using EntityManager.find(). Note that the sequence in the embeddables = 0.

example.Ent{name=1,id=1, embeddables={[example.Embed{sequence=0, value='A'}, example.Embed{sequence=0, value='B'}, example.Embed{sequence=0, value='C'}]}}

Replaced the list of embeddables "A", "B", "C" with "X", "Y", "Z". Note that because the sequences are all zeros, only one of the delete statements will work.

[EL Fine]: 2011-01-19 11:58:17.534--ClientSession(1257121291)--Connection(467120674)--Thread(Thread[main,5,main])--DELETE FROM Ent_EMBEDDABLES WHERE (((SEQUENCE = ?) AND (VALUE = ?)) AND (Ent_ID = ?))
	bind => [0, A, 1]
[EL Fine]: 2011-01-19 11:58:17.578--ClientSession(1257121291)--Connection(467120674)--Thread(Thread[main,5,main])--DELETE FROM Ent_EMBEDDABLES WHERE (((SEQUENCE = ?) AND (VALUE = ?)) AND (Ent_ID = ?))
	bind => [0, B, 1]
[EL Fine]: 2011-01-19 11:58:17.581--ClientSession(1257121291)--Connection(467120674)--Thread(Thread[main,5,main])--DELETE FROM Ent_EMBEDDABLES WHERE (((SEQUENCE = ?) AND (VALUE = ?)) AND (Ent_ID = ?))
	bind => [0, C, 1]

Insert of the new embeddables. The sequence is correct.

[EL Fine]: 2011-01-19 11:58:17.583--ClientSession(1257121291)--Connection(467120674)--Thread(Thread[main,5,main])--INSERT INTO Ent_EMBEDDABLES (Ent_ID, SEQUENCE, VALUE) VALUES (?, ?, ?)
	bind => [1, 1, Y]
[EL Fine]: 2011-01-19 11:58:17.584--ClientSession(1257121291)--Connection(467120674)--Thread(Thread[main,5,main])--INSERT INTO Ent_EMBEDDABLES (Ent_ID, SEQUENCE, VALUE) VALUES (?, ?, ?)
	bind => [1, 0, X]
[EL Fine]: 2011-01-19 11:58:17.584--ClientSession(1257121291)--Connection(467120674)--Thread(Thread[main,5,main])--INSERT INTO Ent_EMBEDDABLES (Ent_ID, SEQUENCE, VALUE) VALUES (?, ?, ?)
	bind => [1, 2, Z]



Reproducible: Always

Steps to Reproduce:
Run the attached test case
Comment 1 Greg Tan CLA 2011-01-18 23:06:43 EST
Created attachment 187072 [details]
Test case for OrderColum on ElementCollection of Embeddables failing to populate
Comment 2 Greg Tan CLA 2011-01-18 23:15:21 EST
Using Derby 10.5.3.0 for the test case
Comment 3 Greg Tan CLA 2011-01-19 20:46:05 EST
Ran the test case against 2.2.0-RC3 and it still fails.
Comment 4 Tom Ware CLA 2011-02-03 09:50:41 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 5 James Sutherland CLA 2013-07-16 14:56:12 EDT
The problem is that you have mapped the sequence in the Embeddable, you should not do this when using an OrderColumn as the index is based on the position in the List.

Remove the mapping for sequence, or at least make it insertable/updateable=false.

If you really want the mapping, then you must maintain it to be correct.

(eclipselink should at most throw an error for this case)
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:34:58 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink