Community
Participate
Working Groups
Build ID: 1.1.2 Steps To Reproduce: 1. Create an entity with an Identity column: @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; 2. Generate the DDL for the entities From the produced DDL you'll see that the field is generated as "ALWAYS AS IDENTITY". With this construct it is impossible to use the generated database for unit testing as identity values cannot be overridden. Instead it should have been generated as "DEFAULT AS IDENTITY". More information: Example of generated table: CREATE TABLE mytab (id BIGINT GENERATED ALWAYS AS IDENTITY NOT NULL, title VARCHAR(255), PRIMARY KEY (id)) Expected output: CREATE TABLE mytab (id BIGINT GENERATED DEFAULT AS IDENTITY NOT NULL, title VARCHAR(255), PRIMARY KEY (id))
Setting Target and priority. For details of what that means, see: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Showstopper for using EclipseLink with dbunit in an in-memory database scenario.
@Allan Lykke Christensen Same problem here (version 1.1.1).. to resolve this issue I have to create a method to reset the sequence in setUp() .. something like that: public void resetSequence(Connection connection, String table, String IdField) throws SQLException { Statement stmt = connection.createStatement(); stmt.executeUpdate( "ALTER TABLE " + table + " ALTER COLUMN " + IdField + " RESTART WITH 1"); stmt.close(); } and in the setUp(): public setUp() { . . . resetSequence(connection, "TABLE_NAME", "TABLE_ID"); FlatXmlDataSet dataset = new FlatXmlDataSet(new File( "dataset.xml")); DatabaseOperation.CLEAN_INSERT.execute(connection, dataset); } @Tom Ware is the bug confirmed?
It sounds like the bug is legitimate. I'd like to encourage those that would like to see this bug fixed to vote for it as votes are one of our main criteria in determining which community bugs to fix.
Tom, looking at the source code I think I've found the solution and it's quite simple .. The class DerbyPlatform.java on line 215 has the following code: /** * INTERNAL: * Append the receiver's field 'identity' constraint clause to a writer. */ public void printFieldIdentityClause(Writer writer) throws ValidationException { try { writer.write(" GENERATED ALWAYS AS IDENTITY"); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } } to resolve the issue the code must change the string "ALWAYS" to "BY DEFAULT" and it will look like these: /** * INTERNAL: * Append the receiver's field 'identity' constraint clause to a writer. */ @Override // I think the annotation is missing here public void printFieldIdentityClause(Writer writer) throws ValidationException { try { writer.write(" GENERATED BY DEFAULT AS IDENTITY"); } catch (IOException ioException) { throw ValidationException.fileError(ioException); } } I'm trying to compile to test it .. Then I send the results .. []s
I am going to tag this as having a "submitted patch". Approximately every week, I go through the bugs with that tag and do some work on the ones that have new information. (Essentially, submitting a good quality patch is a good way to get committer eyes on a bug more quickly) Assuming your patch works, you will have a very good workaround. You can subclass DerbyPlatform and override the method. You can then point at your new class with persistence unit property: eclipselink.target-database=<fully qualified class name>
Created attachment 177530 [details] Patch and Test Case The files contains a patch to correct the bug and a test case to verify the correctness
Checked in submitted patch as submitted. Tested manually with JPA IDENTITY tests Reviewed by: Tom Ware - reviewed customer submitted fix
iplog+ moved to patch.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink