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

  • Home
  • SEARCH
  • 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 8820673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:39:58+00:00 2026-06-14T05:39:58+00:00

I have the following class: @Entity @Table(name = USERS) public class User { private

  • 0

I have the following class:

@Entity
@Table(name = "USERS")
public class User {

    private Long userID;

    @Id
    @Column(name = "userID")
    @GeneratedValue(generator = "increment")
    @GenericGenerator(name = "increment", strategy = "increment")
    public Long getUserID() {
        return userID;
    }

    @Column(nullable = false)
    private boolean isActive;

    @Column(nullable = false, unique = true)
    private String email;

    @Column(nullable = false)
    private String password;


    @Column
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar lastLoggedIn;

    @Column(nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar createdDate;

    @Version
    private Integer version;

    public String getEmail() {
        return email;
    }

    public boolean isActive() {
        return isActive;
    }

    public void setActive(boolean isActive) {
        this.isActive = isActive;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Calendar getLastLoggedIn() {
        return lastLoggedIn;
    }

    public void setLastLoggedIn(Calendar lastLoggedIn) {
        this.lastLoggedIn = lastLoggedIn;
    }

    public Calendar getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Calendar createdDate) {
        this.createdDate = createdDate;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public void setUserID(Long userID) {
        this.userID = userID;
    }

    public User(Long userID, String email, String password, Calendar lastLoggedIn, Calendar createdDate, Integer version) {

    }

    // No argument constructor
    public User() {}
}

When I run my application, Hibernate loads the configuration and creates the table for Users. I’m using Postgresql. This is the SQL statement being generated (logged by hibernate):

Hibernate: create table USERS 
           (userID int8 not null, active boolean not null, createdDate timestamp, 
            email varchar(255), lastLoggedIn timestamp, 
            password varchar(255), version int4, primary key (userID))

Why is it that a boolean is created as not null and a String/Timestamp is not? I won’t there to be an exception if you try to insert a User without an email or password, but with this generated schema it won’t. Is there another way to force Hibernate to create the field as not nullable?

  • 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-14T05:40:00+00:00Added an answer on June 14, 2026 at 5:40 am

    From 5.1.4.1.2. Access type :

    By default the access type of a class hierarchy is defined by the
    position of the @Id or @EmbeddedId annotations. If these annotations
    are on a field, then only fields are considered for persistence and
    the state is accessed via the field. If there annotations are on a
    getter, then only the getters are considered for persistence and the
    state is accessed via the getter/setter.

    As you annotate @Id on the getter , you are using property access. So , hibernate will ignore all mapping annotations marked on the fields and only use annotations on getters to generate DDL . Because there are no annotations on getters , default settings are used .

    You should get your desired result if you change to annotate @Id on the userID instead of getUserID()

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

Sidebar

Related Questions

Say, I have following entities: @Entity public class A { @Id @GeneratedValue private Long
I have the following mapping: @Entity @Table(name = Prequalifications) public class Prequalification implements Serializable
I have the following entities: @Entity public class Owner{ @Id @Column(name = OWNER_ID) @OneToMany()
I have the following property defined: @Entity @Table(name = person) public class Person extends
I have a parent-child relationship: @Entity @Table(name = user) public final class User {
I have the following entity class : @Entity @Table(name = THE_TREE, catalog = ,
I have an entity mapped as following: @Entity @Table(name = Groups) @IdClass(value = GroupId.class)
I have the following two entities: @Entity class Relation{ @ManyToOne private User user; //some
Assume I have the following two classes: public class User : Entity { public
I have the following tables/views Users (View) -> UserId -> Name Roles (Table) ->

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.