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 8240727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:35:23+00:00 2026-06-07T20:35:23+00:00

I have an Insert statement to a table which has a primary key of

  • 0

I have an Insert statement to a table which has a primary key of dep_id and emp_id. My java program generates a new emp_id for a new record and inserts it. What is happening is if for example, I have dep_id = 100 and emp_id = 25, I am not able to insert a record where dep_id = 100 and emp_id = 26, but I can for dep_id = 100 and emp_id = 27. I checked thru select statements if something of that combination (dep_id = 100 and emp_id = 26) exists. There is nothing of that sort. I still did a
DELETE from where dep_id = 100 and emp_id = 26 and Commit
just to be sure and then tried to insert, but still it does not work. What might be wrong? Follwing is the code: Modified DDL and Insert statement(Obtained from Eclipse console)

                                                                                    CREATE  TABLE "TestDB"."table1" 
 (  "dep_id" NUMBER(20,0), 
"emp_id" NUMBER(20,0), 
"STATUS" VARCHAR2(10 BYTE), 
"PRO_LEVEL" VARCHAR2(14 BYTE), 
"new_sql_stmt" VARCHAR2(4000 BYTE), 
"DEL_TEM" VARCHAR2(500 BYTE), 
"tab_name" VARCHAR2(4000 BYTE), 
"COL_NAME" VARCHAR2(4000 BYTE), 
"QUERY_TYPE" VARCHAR2(4000 BYTE), 
"NAME" VARCHAR2(4000 BYTE), 
"DT_MODIFIED" DATE DEFAULT SYSDATE

)

  CREATE UNIQUE INDEX "TestDB"."table1_PK" ON "TestDB"."table1" ("dep_id", "emp_id") 


     INSERT into table1            (dep_id,emp_id,status,new_sql_stmt,tab_name,col_name,query_type,NAME)values('100','26','Unlock','INSERT into testTab(id_some,nm_some,id_some_origin,flag,some_code,author,order) values  (''S11111111'',''trialSome00'','''',''y'','''',''100'',0)','testTab','nm_some','INSERT','trialSome00')

Please note that the Insert statement itself has another Insert statement as the value. This Insert statement(The main one) is used in many other places in the app. Also, The dep_id that I use 100 is a test dep_id. Nobody uses it but me.

  • 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-07T20:35:24+00:00Added an answer on June 7, 2026 at 8:35 pm

    Create an Oracle sequence:

    CREATE SEQUENCE emp_id_seq MINVALUE 1 START WITH 1 INCREMENT BY 1; 
    

    Now you can either call the “nextval” method on that sequence (this can be done with JDBC or almost every ORM if not all of them) from within your code, or you can place a trigger on that column that automatically gets the nextval from the sequence and inserts it in the table any time you do an insert (IIRC on oracle you would use the ‘BEFORE INSERT’ operator in your trigger).

    e.g.

    create or replace trigger mytable_emp_id_trigger
    before insert on mytable
    for each row
    begin
        select emp_id_seq.nextval into :emp.id from dual;
    end;
    /
    

    Doing it this way is thread safe and you should never see a conflict like this occur.

    If you insist on doing it within java code (say the DBA’s won’t let you create another sequence, but why-ever not I’d be surprised if they didn’t), then you’ll have to make that method thread safe. Likely best to create a singleton (you can create singleton EJBs) with a synchronized method to provide the next value. You get your id’s from that singleton class, not any other class or ejb to avoid issues like you are having now (whether or not the current issue is because of this, what you are experiencing now is typical of multiple threads coming into conflict with unsynchronized methods in a multithreaded environment).

    In the meantime, make use of your debugger and watch your variables to see what your existing code is producing if you really want to understand what is happening. Debuggers and watches are your friends. Your best friends.

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

Sidebar

Related Questions

I have added a record to my table which auto-increments the primary key. I
I have a table which uses two columns to represent its primary key, a
I have a table Survey_Data_Response that is populated with an 'insert into' statement from
I have a table:'Categories' which has two fields:Category_ID and Category. Data in Category_ID field
i have a table which has many fields but i want to get count
I have a table which has more than 380 million records. I have a
I have a MySQL table which has a field for email addresses which is
HI, I have an insert statement in a Stored Procedure that requires the value
Hey guys quick question, I currently have an insert statement $query= INSERT into new_mail
I have one multi-row INSERT statement (300 or so sets of values) that I

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.