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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:40:25+00:00 2026-05-26T17:40:25+00:00

I have created a seam applcation with Hibernate(default) a ORM provider. While persisting an

  • 0

I have created a seam applcation with Hibernate(default) a ORM provider. While persisting an entity, it throws following error:

Caused by: java.sql.SQLException: Field 'COUNTRY_ID' doesn't have a default value
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)

Its thrown because the Primary key is not generated by Hibernate before persisting entity.

@Entity
@Table(name = "country")
public class Country implements java.io.Serializable {

private Integer countryId;
//other instance variables...

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "COUNTRY_ID", unique = true, nullable = false)
public Integer getCountryId() {
return this.countryId;
}

public void setCountryId(Integer countryId) {
this.countryId = countryId;
}

When I make changes in ‘Country’ Table, i.e make COUNTRY.COUNTRY_ID as AUTO_INCREMENT (MySQL database) then the above code persists Country entity. Even after trying strategy

@GeneratedValue(strategy = GenerationType.IDENTITY)

error occurs if I don’t make COUNTRY_ID as AUTO_INCREMENT.

So, is it necessary that Primary keys should be made Auto Increment in table? Why doesn’t Hibernate create a unique primary key (using HiLo algorithm) before persisting the entity if the primary key is not marked as AUTO_INCREMENT in database table.

Thanks in advance.

Regards

  • 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-26T17:40:25+00:00Added an answer on May 26, 2026 at 5:40 pm

    GenerationType.AUTO means that hibernate will select a generation strategy depending on the database capabilities: for MySQL will select the identity strategy. In your case specifying GenerationType.AUTO is the same with GenerationType.IDENTITY.

    In turn, GenerationType.IDENTITY requires to have an auto increment on your id column.

    You should try other strategies if you want hibernate to assign values to your id column: for example hilo. But letting hibernate assign values for your id columns is recommended only for testing.

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

Sidebar

Related Questions

I created a seam application using seam-gen. I am getting below error while navigating
I have created my own custom role provider class SGI_RoleProvider and configured properly. Everything
i'm using prettyfaces 3.1.0 with JSF1.2 and Seam 2.2.0. I have the following pretty-config.xml:
I am running a JBoss Seam web application with Hibernate as the persistence provider.
I'm currently working on a seam project and have a problem. I just created
For my current project I'm working with JSF, Seam and Hibernate and I have
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have created a template for Visual Studio 2008 and it currently shows up
I have created a custom dialog for Visual Studio Setup Project using the steps
I have created a PHP-script to update a web server that is live inside

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.