Community
Participate
Working Groups
Build ID: I20080617-2000 Steps To Reproduce: 1. Import attached project archive (zip) into Eclipse 3.4 and a JavaSE-1.6 EE available. 2. Execute the 'pkbug.Main' class. This should result in a lot of output to the console and a final error about a constraint violation on a duplicated primary key. More information: Given the following classes and persistence.xml file -- -- ThreadInfo.java -- package pkbug; import javax.persistence.Embeddable; @Embeddable public class ThreadInfo { private long id; private String name; public ThreadInfo() {} public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } -- MachineState.java -- package pkbug; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class MachineState { @Id private long id; @AttributeOverrides( { @AttributeOverride(name = "id", column = @Column(name = "THREAD_ID")), @AttributeOverride(name = "name", column = @Column(name = "THREAD_NAME")) }) private ThreadInfo thread; public MachineState() {} public long getId() { return id; } public void setId(long id) { this.id = id; } public ThreadInfo getThread() { return thread; } public void setThread(ThreadInfo thread) { this.thread = thread; } } -- persistence.xml -- <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="pkbug" transaction-type="RESOURCE_LOCAL"> <class>pkbug.MachineState</class> <class>pkbug.ThreadInfo</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> </persistence-unit> </persistence> EclipseLink will dynamically generate the following DDL statement to create the table. CREATE TABLE MACHINESTATE (ID BIGINT, THREAD_ID BIGINT NOT NULL, THREAD_NAME VARCHAR(255), PRIMARY KEY (THREAD_ID)) Note that 'PIMARY KEY' is on 'THREAD_ID' instead of 'ID', which is the field that has the @Id annotation.
Created attachment 107767 [details] Java Project Archive export; contains all necessary dependencies
I discovered a work-around. If you declare the correct primary key field after the embedded entity's field, the primary key field is picked correctly. The workaround version of MachineState.java from comment #1 would look something like this. @Entity public class MachineState { @AttributeOverrides( { @AttributeOverride(name = "id", column = @Column(name = "THREAD_ID")), @AttributeOverride(name = "name", column = @Column(name = "THREAD_NAME"))}) private ThreadInfo thread; @Id private long id; ... }
BTW - If someone can point the way to the bit of code this is might be localized to, I'll try to do my bit and come up with a fix.
Moving into 1.0.1 based on Bug triage
Created attachment 110456 [details] Proposed changes
(In reply to comment #5) > Created an attachment (id=110456) [details] > Proposed changes > Regarding the addition of the test sources in this patch. Can Oracle claim copyright (in the header of the file) over these files, which were mostly sourced from public postings to this bug?
Created attachment 110460 [details] Updated patch, namely copyrights.
Changes have been submitted. Reviewed by: Tom Ware New tests: testBug241308 added to the DDLGenerationJUnitTestSuite along with the necessary new model classes.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink