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

  • SEARCH
  • Home
  • 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 7780015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:47:41+00:00 2026-06-01T18:47:41+00:00

I’m using Oracle database and I have sequence and trigger for generating and storing

  • 0

I’m using Oracle database and I have sequence and trigger for generating and storing ID before insert.

CREATE SEQUENCE CASE_SEQ START WITH 1001 INCREMENT BY 1 NOMAXVALUE; 

CREATE OR REPLACE TRIGGER CASE_TR_SEQ
BEFORE INSERT ON CASE FOR EACH ROW
BEGIN
  SELECT CASE_SEQ.NEXTVAL INTO :NEW.CASE_ID FROM DUAL;
END;
/

Then I have simple entity with property:

@Id
@Column(name = "CASE_ID", insertable = false, updatable = false)
private Long caseId;

…when I try build project I’m getting:

Exception [EclipseLink-46] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: There should be one non-read-only mapping defined for the
primary key field [CASE.CASE_ID].

When I remove either insertable or updatable keyword, then it works. I know that there is a lot of solutions how generate ID using JPA, also JPA can use (call) oracle sequence to set (generated) ID. But I try understand why is my solutions wrong. Why I can’t use both keywords together with the @Id annotation? My thought is: I want to prohibit insert or update caseId by JPA.

1) What is the proper soulution? Should I use only @Id:

@Id
@Column(name = "CASE_ID")
private Long caseId;

or is better (safer) define insertable=false also:

@Id
@Column(name = "CASE_ID", insertable = false)
private Long caseId;

2) I understand that updatable=false for @Id does not have meaning (update Primary Key does not have meaning but it is possible by raw sql), but what does it mean (do you have some example when it is beneficial):

@Id
@Column(name = "CASE_ID", updatable = false)
private Long caseId;

EDIT 2012-04-13

I made some tests:

Entity

@Id
@Column(name = "CASE_ID")
private Long caseId;

JPA log

INSERT INTO CASE (CASE_ID, CASE_DATE, INFO) VALUES (?, ?, ?)
bind => [3 parameters bound]|#]

So this is not safe, because JPA tries store CASE_ID (which is then replaced by ID from Oracle sequence by trigger).

Entity

@Id
@Column(name = "CASE_ID", insertable = false)
private Long caseId;

Create method

public void createCase(final Case caseData) {
    caseData.setCaseId(-1001L);
    em.persist(caseData);
}

JPA log

INSERT INTO CASE (CASE_DATE, INFO) VALUES (?, ?)
bind => [2 parameters bound]|#]

It is good, because the CASE_ID is not part of insert command.

And Update of CASE_ID is not possible because annotation ID:

public void update() {
    Case update = em.find(Case.class, 1023L);
    update.setCaseId(1028L);
}

Exception [EclipseLink-7251] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [caseId] of class
[com.wordpress.kamiluv.jsfprototype.model.entity.Case] is mapped to a primary
key column in the database. Updates are not allowed.

So now the last version looks as the most safe, right?

  • 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-01T18:47:43+00:00Added an answer on June 1, 2026 at 6:47 pm

    You are currently saying with your JPA annotations that you have an @Id column that cannot be inserted or updated in any way. You must be able to set the id before inserting or updating, but JPA does not know how to do so. You will need to use the @GeneratedValue annotation on the @Id to tell JPA what strategy to use (one of: TABLE,SEQUENCE,IDENTITY,AUTO) if you do not want the id to be set in your code.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,

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.