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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:41:39+00:00 2026-05-18T22:41:39+00:00

Hello and happy new year for everyone. I need to insert a record at

  • 0

Hello and happy new year for everyone.

I need to insert a record at the end of a table (the table has not set autoincrement) using JPA.

I know I could get the last id (integer) and apply to the entity before insert, but how could that be done? Which way would be most effective?

  • 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-05-18T22:41:40+00:00Added an answer on May 18, 2026 at 10:41 pm

    Well, while i do not know where the end of a table really is, JPA has a lot of options for plugging in ID generators.

    One common option is to use a table of its own, having a counter for each entity you need an ID for (from http://download.oracle.com/docs/cd/B32110_01/web.1013/b28221/cmp30cfg001.htm).

    @Id(generate=TABLE, generator="ADDRESS_TABLE_GENERATOR")
    @TableGenerator(
    name="ADDRESS_TABLE_GENERATOR", 
        tableName="EMPLOYEE_GENERATOR_TABLE", 
        pkColumnValue="ADDRESS_SEQ"
    )
    @Column(name="ADDRESS_ID")
    public Integer getId() {
        return id;
     }
    

    …other “Generator” strategies to be googled…

    EDIT

    I dare to reference @a_horse_with_no_name as he says he does not know about JPA. If you want to use native mechanisms like sequence (that are not available in every DB) you can declare such a generator in JPA, too.

    I do not know what issues he encountered with the table approach – i know large installations running this successfully. But anyway, this depends on a lot of factors besides scalability, for example if you want this to be portable etc. Just lookup the different strategies and select the appropriate.

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

Sidebar

Related Questions

Hello and Happy New Year all! While thinking about new project I decided to
Hello all happy holidays! :) I'm trying to insert comments in my wordpress blog
Hello I need to do something like this: UPDATE tbl SET pozn=CONCAT(pozn, '+attach_str+') WHERE
Hello Im using HTTParty to call for a remote json file that I need
I'm serialising a List of a class and I'm not happy about the generated
Hello and thanks for looking! Background I am designing a greenfield application using .NET4
A package I am using, gosqlite, has a method with a variadic parameter where
I have got html as below <a href= data-href=/somefile.php?id=10&refcode=/test.php>Hello</a> and I need to replace
Let's say I have: <input type=text id=first attribute1=test attribute2=hello attribute3=happy> <input type=text id=first attribute1=test
Hello Stackoverflow community, for a little game I need to display an octagon (

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.