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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:48:02+00:00 2026-05-17T14:48:02+00:00

I use Eclipselink as my JPA provider, how can I make a field auto

  • 0

I use Eclipselink as my JPA provider, how can I make a field auto increment?

  • 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-17T14:48:02+00:00Added an answer on May 17, 2026 at 2:48 pm

    I just want an auto-increment field for 1 entity.

    Yes, I get that, this is what you wrote in your question. But it can be interpreted in several ways and repeating the same thing without clarifying doesn’t help much 🙂

    So does Pascal’s way work or I have to do what Bytecode suggest, query select (max) counter + 1 from MyEntity, to get the next value, then set it to the design field, the persist?

    If you want to increment a field per entity record (e.g. a “counter” for Order with id=1, another one for Order with id=2), what I suggested would work.

    If you want a behavior similar to a primary key (i.e. an auto-incremented column), it won’t. And in that case, standard JPA doesn’t offer any particular facility (standard JPA only allows GenereatedValue on Id annotated field). The only way I can think of would be to insert another dedicated entity just to get the primary key from it.


    Your exact requirement is unclear but I’m assuming you’re talking about a random field, not the primary key. In that case, you could maybe use life cycle callbacks methods:

    @Entity
    public class MyEntity {
        ...
        private int counter;
        ...
    
        @PrePersist
        @PreUpdate
        protected void increment() {
             counter = counter + 1;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use JPA persistence for my data models with Eclipselink as the persistence provider.
Can I use JPA 2.0(e.g EclipseLink) with Google App Engine?
I want to use JPA (eclipselink) to get data from my database. The database
I'm struggling with real-world use of JPA (Hibernate, EclipseLink, etc) in a Swing desktop
I am in the midst of changing my JPA code around to make use
I'm using EclipseLink as the JPA provider. Further I'm using the following TABLE_PER_CLASS inheritance
If I use JPA (EclipseLink) to create tables a String type results in a
is there an easy approach to store my model, which I use with EclipseLink,
use the [] symbol in the name of the form field you are submitting
I would like to be able to swap my JPA implementation between EclipseLink &

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.