Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:32:41+00:00 2026-06-15T03:32:41+00:00

EclipseLink seems to be incorrectly passing a null primary key value to Derby when

  • 0

EclipseLink seems to be incorrectly passing a null primary key value to Derby when persisting into a table with generated primary key. Derby returns error of Attempt to modify an identity column in this case. Derby needs a SQL statement that excludes the id value. My question is how do I coerce EclipseLink to send the right SQL? Details follow…

I am using Eclipselink to map to a Derby database (v10.8.1.2) under the latest Netbeans 7.3beta2.

The database table primary key is auto generated:

CREATE TABLE STUDENT_BATCH ( 
    ID bigint PRIMARY KEY
        GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
    FILENAME varchar(200) NOT NULL,
    SCHOOLBOARD varchar(100) NOT NULL,
    CREATE_TS timestamp NOT NULL,
    CONTACT_INFO varchar(200),
    NOTES varchar(2000),
    BOARD_NAME varchar(100)
)
;

The corresponding jpa class specifies that the id is generated using strategy of identity:

@Entity
@Table(name = "STUDENT_BATCH")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "StudentBatch.findAll", query = "SELECT s FROM StudentBatch s")})
public class StudentBatch implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Long id;
    @Basic(optional = false)
    @Column(name = "FILENAME")
    private String filename;
    @Basic(optional = false)
    @Column(name = "SCHOOLBOARD")
    private String schoolboard;
    @Basic(optional = false)
    @Column(name = "CREATE_TS")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTs;
    @Column(name = "CONTACT_INFO")
    private String contactInfo;
    @Column(name = "NOTES")
    private String notes;
    @Column(name = "BOARD_NAME")
    private String boardName;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "studentBatchId")
    private Collection<StudentRecord> studentRecordCollection;

    methods etc follow...

When I go to persist the class, I do not specify an id so that Derby will provide the id.

                StudentBatch sb = new StudentBatch();
                sb.setBoardName(meta.get("BOARD NAME"));
                sb.setContactInfo(meta.get("CONTACT INFO"));
                sb.setCreateTs(new Date());
                sb.setFilename(event.getFile().getFileName());
                sb.setNotes(meta.get("NOTES"));
                sb.setSchoolboard(meta.get("SCHOOL BOARD"));
                _logger.debug("persisting batch");
                em.persist(sb);
                _logger.debug("flushing");
                em.flush();
                _logger.debug("flushed");

Eclipselink, however, passes the id to derby as null and Derby gives error Attempt to modify an identity column:

INFO: DEBUG  11710 27 Nov 2012 18:17:10,558 [http-thread-pool-8080(4)] (FileUploadController.java:75) - persisting batch
INFO: DEBUG  11713 27 Nov 2012 18:17:10,561 [http-thread-pool-8080(4)] (FileUploadController.java:77) - flushing
WARNING: Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Attempt to modify an identity column 'ID'. 
Error Code: -1
Call: INSERT INTO STUDENT_BATCH (ID, BOARD_NAME, CONTACT_INFO, CREATE_TS, FILENAME, NOTES, SCHOOLBOARD) VALUES (?, ?, ?, ?, ?, ?, ?)
bind => [7 parameters bound]
Query: InsertObjectQuery(ca.ontario.mhltc.studentupload.model.StudentBatch[ id=null ])
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)

This makes some sense to me since if I try to execute an insert on sql command line with the id field specified I get an error too.

INSERT INTO STUDENT_BATCH (id, BOARD_NAME, CONTACT_INFO, CREATE_TS, FILENAME, NOTES, SCHOOLBOARD)
VALUES (null, 'abc', 'def', current_timestamp, 'aaa', 'aabb', '1234');

gives me this:

Error code -1, SQL state 42Z23: Attempt to modify an identity column 'ID'. 
Line 1, column 1

Execution finished after 0 s, 1 error(s) occurred.

however, this insert statement is successful:

INSERT INTO STUDENT_BATCH (BOARD_NAME, CONTACT_INFO, CREATE_TS, FILENAME, NOTES, SCHOOLBOARD)
VALUES ('abc', 'def', current_timestamp, 'aaa', 'aabb', '1234');

returns

Executed successfully in 0.002 s, 1 rows affected.
Line 1, column 1

Execution finished after 0.002 s, 0 error(s) occurred.

Seems to me that Eclipselink should know about how Derby handles identity columns and should not pass the id column at all on the insert statement. Is there a workaround for this or I should I just dump Derby and use some other database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:32:42+00:00Added an answer on June 15, 2026 at 3:32 am

    EclipseLink does not include the Id in the INSERT for Derby IDENTITY, so you have something odd going on.

    Did you previously use another generator strategy and not recompile/deploy your code correctly?

    Also try setting your platform using the”eclipselink.target-database”=”Derby” in your persistence.xml.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There's seems a problem between Eclipslink and Derby Auto-Icrement column when i insert value
I have a precision problem storing a float value in mysql via jpa (EclipseLink).
The link quoted on the EclipseLink/Maven wiki ends on an Error 403 page on
I have run into a EclipseLink issue with multiple queries running against the DB
I'm using the latest EclipseLink version with MySQL 5.5 (table type InnoDB). I'm inserting
I am using Eclipselink v2.3.3 I am getting this error Error compiling the query
it seems like everything i persist, it keep entering 401 into the id, causing
I'm using EclipseLink 2.3.1 to model self referencing table with JPA 2. I get
I'm kicking the tires on EclipseLink(2.3.0) and found something that seems severely wrong. The
I am using EclipseLink dynamic moxy for jaxb. When I try to set an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.