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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:12:51+00:00 2026-05-27T20:12:51+00:00

Im trying to insert a record in a postgres db but insertion fails. When

  • 0

Im trying to insert a record in a postgres db but insertion fails.

When trying to select data, selection works fine, so i suppose its not a spring-hibernate configuration error

environment: Spring 3.1, Hibernate 3.6, Postgres 9.1

here is my code :

Entity class:

@Entity
public class Person implements Serializable {

    @Id
    @Column(insertable=false, updatable=false)
    @Type(type="java.lang.Long")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="PERSON_SEQ")
    @SequenceGenerator(name="PERSON_SEQ", sequenceName="PERSON_SEQ", allocationSize=1)
    private Long id;

    @Column
    private String firstName;
}

My Dao:

@Repository
public class PersonDao extends BaseDao
  public void insertPerson(){
    super.getHibernateTemplate().execute(new HibernateCallback() {
        @Override
        public Object doInHibernate(Session session) throws HibernateException, SQLException {

          Person p = new Person();
          p.setFirstName("george");             
          session.persist(p);
          return null;
        }
    });
}
}

At the first time the application is deployed, a new sequence is created in postgres

  CREATE SEQUENCE person_seq
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;
  ALTER TABLE person_seq
  OWNER TO postgres;

The hibernate sql output during sql insert is:

Hibernate: 
select
    nextval ('PERSON_SEQ')
Hibernate: 
insert 
into
    Person
    (firstName, lastName, money, id) 
values
    (?, ?, ?, ?)

but it never inserts the record, even if the sequence increments by 1

  • 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-27T20:12:51+00:00Added an answer on May 27, 2026 at 8:12 pm

    It looks like the transaction is never committed.
    Have you configured your transaction manager with Spring or defined @Transactional on your service that calls insertPerson?

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

Sidebar

Related Questions

I am trying to insert a record into a table using Linq but get
Can anyone help with a Postgres syntax problem? I'm trying to insert a record,
I am trying to insert a record in Excel using asp.net but it is
I am trying to insert a record and get its newly generated id by
I am trying to insert a standard record into my db using linq2db, but
I am trying to insert a record. This code worked but has stopped working
I'm trying to insert a database record inside a loop in C#. It works
I am experiencing a very frustrating issue when trying to insert a new record
I'm trying to figure out the best way to insert a record into a
I am trying to insert a calculated date when record is written. Datatype is

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.