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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:56:12+00:00 2026-06-08T00:56:12+00:00

After trying different suggested solutions I haven’t managed to figure out this one. I’m

  • 0

After trying different suggested solutions I haven’t managed to figure out this one.

I’m using hibernate 3.6 and mysql 5.x and trying to persist my entity (I excluded the getters & setters):

@Entity
@Table(name = "brand_managers")
public class BrandManager implements Serializable {

    /** Serial version unique id */
    private static final long serialVersionUID = -7992146584570782015L;

    /*--- Members ---*/

    /** The unique, internal ID of the entity. */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private long id;

    /**
     * The creation time of this user
     */
    @Temporal(TemporalType.DATE)
    @Column(name = "creation_time")
    protected Calendar creationTime;

    /**
     * The hashed password
     */
    @Column(name = "password")
    protected String password;

    @Column(name = "first_name")
    protected String firstName;

    @Column(name = "last_name")
    protected String lastName;

    @Column(name = "email")
    protected String eMail;

    @Column(name = "address1")
    protected String address1;

    @Column(name = "address2", nullable = true)
    protected String address2;

    @Column(name = "city")
    protected String city;

    @Column(name = "state")
    protected String state;

    @Column(name = "zip", nullable = true)
    protected String zip;

    @Column(name = "country")
    protected String country;

    @Column(name = "phone")
    protected String phone;

    @Column(name = "brand_id")
    protected int brandId;

    /*--- Constructors ---*/

    /**
     * default
     */
    public BrandManager() {
    setCreationTime(Calendar.getInstance());
    }

    /**
     * @param password
     *            The hashed user password
     * @param firstName
     *            The first name
     * @param lastName
     *            The last name
     * @param eMail
     *            User eMail
     * @param address1
     *            User address
     * @param address2
     *            Another user address
     * @param city
     *            City of residence
     * @param state
     *            User state
     * @param country
     *            Country of of residence
     * @param phone
     *            User phone number
     * @param The
     *            id of the brand, managed by this brand manager
     */
    public BrandManager(String password, String firstName, String lastName, String eMail, String address1, String address2, String city,
        String state, String zip, String country, String phone, int brandId) {
    this();
    this.password = password;
    this.firstName = firstName;
    this.lastName = lastName;
    this.eMail = eMail;
    this.address1 = address1;
    this.address2 = address2;
    this.city = city;
    this.state = state;
    this.zip = zip;
    this.country = country;
    this.phone = phone;
    this.brandId = brandId;
    }

    /*--- Overridden Methods ---*/

    /**
     * Equality is based on the e-mail of this brand manager
     */
    @Override
    public boolean equals(Object obj) {

    if ((obj == null) || !(obj instanceof BrandManager)) {
        return false;
    }

    // reference comparison
    if (obj == this) {
        return true;
    }

    final BrandManager other = (BrandManager) obj;

    return new EqualsBuilder().append(geteMail(), other.geteMail()).isEquals();
    }

    /**
     * The unique hash code based on the e-mail of this brand manager
     */
    @Override
    public int hashCode() {
    return new HashCodeBuilder().append(this.geteMail()).toHashCode();
    }

    /**
     * Returning first name, last name and email.
     */
    @Override
    public String toString() {
    return ("First name: " + getFirstName() + ", Last name: " + getLastName() + ", E-Mail: " + geteMail());
    }

I created a corresponding table in my DB:

CREATE TABLE `brand_managers` (
  `id` bigint(20) NOT NULL,
  `creation_time` datetime NOT NULL,
  `password` varchar(45) NOT NULL,
  `first_name` varchar(45) NOT NULL,
  `last_name` varchar(45) NOT NULL,
  `email` varchar(45) NOT NULL,
  `address1` varchar(45) NOT NULL,
  `address2` varchar(45) DEFAULT NULL,
  `city` varchar(45) NOT NULL,
  `state` varchar(45) NOT NULL,
  `zip` varchar(45) DEFAULT NULL,
  `country` varchar(45) NOT NULL,
  `phone` varchar(45) NOT NULL,
  `brand_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_UNIQUE` (`id`),
  UNIQUE KEY `email_UNIQUE` (`email`)

When trying to persist a new instance of this entity I get:

2012-07-21 12:24:03 JDBCExceptionReporter [WARN] SQL Error: 1364, SQLState: HY000
2012-07-21 12:24:03 JDBCExceptionReporter [ERROR] Field 'id' doesn't have a default value
2012-07-21 12:24:03 HibernateTask [ERROR] Hibernate exception caught in me.comocomo.server.dao.objectModel.club.register.BrandManager - could not insert: [me.comocomo.server.dao.objectModel.club.register.BrandManager]
2012-07-21 12:24:03 AssertionFailure [ERROR] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: null id in me.comocomo.server.dao.objectModel.club.register.BrandManager entry (don't flush the Session after an exception occurs)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:82)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)

Now, I have managed to resolve it by using auto-increment, Meaning that when I altered the id column (which is the PK) as follows:

ALTER TABLE `MYDB`.`brand_managers` CHANGE COLUMN `id` `id` BIGINT(20) NOT NULL AUTO_INCREMENT  ;

It worked just fine!

I don’t mind actually working this way (using auto-incremented id) but I simply don’t understand why this is the only constellation that actually works. Why can’t I generate a long type unique id using the “IDENTITY” generator?

  • 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-06-08T00:56:14+00:00Added an answer on June 8, 2026 at 12:56 am

    That’s what an IDENTITY generator is: a generator that relies on an auto-increment field to generate the unique ID, and asks the database for the generated ID once the record has been saved.

    If you want the ID to be generated in memory you could use a UUID generator.

    Most of the generators ask the database to generate the ID, because it’s the only component in the architecture that is reliable and shared. If you have several applications each saving records in the same table, and each using their own generator, it will obviously lead to conflicts. Asking the database solves this problem: every application agrees to use an auto-increment field, or a sequence, or a table, and everything is fine.

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

Sidebar

Related Questions

After some time researching and trying different things I still cannot get my @ExceptionHandler
I am trying to use MPI to sort digits, after sorting by the different
After trying this simple console input with 5, the result is shown as 53
After trying to figure how to have an effective word counter of a string,
After trying out VS2010b2 also my VS2008 installation changes the versions of solution and
I think my problem may be quite simple, but after trying different approaches I
After wasting two days with this question (and trying to make it work), I've
After trying to work on someone else's code, and so many different iterations, I
I am currently trying to figure out how to connect to another server via
I'm sure someone's had this problem before but I can't figure it out because

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.