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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:06:21+00:00 2026-05-20T02:06:21+00:00

I am using Hibernate 3.3 and PostgreSQL 8.x and would like to use Hibernate

  • 0

I am using Hibernate 3.3 and PostgreSQL 8.x and would like to use Hibernate annotations to map an auto-incremented column which is NOT a primary key.

It doesn’t matter if the column is mapped using SERIAL type or sequences in Postgres as long as it gets auto-incremented by the database and not by Hibernate. I tried the following mappings, but they always generated null orderId.

@Column(name = "orderId", insertable = false)
@Generated(GenerationTime.INSERT)
//@GeneratedValue(strategy = javax.persistence.GenerationType.AUTO)
private Integer orderId;

I will appreciate any help with this.

Thanks

  • 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-20T02:06:22+00:00Added an answer on May 20, 2026 at 2:06 am

    The following mapping should work fine:

    @Column(name = "orderId")
    @Generated(GenerationTime.INSERT)
    private Integer orderId;
    

    Note, however, that generated value for freshly saved objects is not available until session is flushed.

    EDIT: Note that this mapping doesn’t affect doesn’t make Hibernate to create a column of type serial during schema generation, since Hibernate doesn’t know anything about the nature of value generation at the database side. Therefore, if you want Hibernate to create a column with a proper type, you need to specifiy it explicitly:

    @Column(name = "orderId", columnDefinition = "serial")
    @Generated(GenerationTime.INSERT)
    private Integer orderId;
    

    And on a recent Hibernate version (4.3), you can use this:

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long orderId;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Glassfish v2, Hibernate with Annotations+EntityManager and Postgresql 8.4. I am also
I'm seeing strange behaviour when using PostgreSQL in a Hibernate/JPA environment with a single
When using Hibernate 2nd level cache and query cache and not specifying anything inside
I'm not using hibernate and that's not a valid alternative at all. I developed
I'm trying to use PostgreSQL as the database for Hibernate/JPA. However, I get an
I'm debeloping a Java Swing application, which persists the information through Hibernate, currently using
I am setting up a project using Hibernate 3.3.1 GA and PostgreSQL 8.3 .
Are there any issues with using a byte[] as a primary key in a
This is a JavaEE6 application using Hibernate and PostgreSQL. Users are created in the
There's an enterprise application using Java + Hibernate + PostgreSQL. Hibernate is configured via

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.