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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:28:01+00:00 2026-05-16T21:28:01+00:00

@Entity @Table(name = J_CNTRY) public class CountryEntity { @Id @GeneratedValue(strategy = GenerationType.TABLE, generator =

  • 0
@Entity
@Table(name = "J_CNTRY")
public class CountryEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "myTableGenerator")
    @TableGenerator(name = "myTableGenerator", allocationSize = 5, pkColumnName = "pkName", valueColumnName = "pkValue", table = "j_cntry_pk_table")
    private Long id;

    private String country;

    @Generated(GenerationTime.INSERT)
    @Column(name = "CREATION_TIME", columnDefinition = "DATE default '15-JUL-1980'", insertable = false)
    private Date creationTime;

    public CountryEntity() {
    }

    public Long getId() {
        return id;
    }

    public void setId(final Long id) {
        this.id = id;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(final String country) {
        this.country = country;
    }

    public Date getCreationTime() {
        return creationTime;
    }

    @Override
    public String toString() {
        return "Country [id=" + id + ", country=" + country + ", creationTime="
                + creationTime + "]";
    }

}

I’m expecting the value ’15-JUL-1980′ to be inserted for each row IF I DONOT set its value.

But its not working as expected. Am I doing anything wrong here?

For some reasons, I want to set the default value at the application and Not at the database.

UPDATE:

Initially i tried without ‘insertable = false’ only.

As a newbie, I was trying different options and had kept that option.

Here is the test case which I’m running:

@Test
    public void testCreateCountry4() {
        final CountryEntity a1 = new CountryEntity();
        a1.setCountry("Xxxx");
        final Session currentSession = sessionFactory.getCurrentSession();
        final Long savedId = (Long) currentSession.save(a1);
        System.out.println("Saved with ID = " + savedId);
        currentSession.flush();
        System.out.println("Saved object = " + a1);
        assertNotNull(savedId);
    }

and the output it has produced:

Saved with ID = 85
Hibernate: 
    /* insert entities.CountryEntity
        */ insert 
        into
            J_CNTRY
            (country, id) 
        values
            (?, ?)
Hibernate: 
    /* get generated state entities.CountryEntity */ select
        countryent_.CREATION_TIME as CREATION3_2_ 
    from
        J_CNTRY countryent_ 
    where
        countryent_.id=?
Saved object = Country [id=85, country=Xxxx, creationTime=null]

Table:

CREATE TABLE "FOO"."J_CNTRY" 
   (    "ID" VARCHAR2(255 BYTE) NOT NULL, 
    "COUNTRY" VARCHAR2(255 BYTE), 
    "CREATION_TIME" DATE, 
     CONSTRAINT "J_CNTRY_PK" PRIMARY KEY ("ID")
}
  • 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-16T21:28:01+00:00Added an answer on May 16, 2026 at 9:28 pm

    I’m expecting the value ’15-JUL-1980′ to be inserted for each row IF I DO NOT set its value.

    Actually, the creationTime will never be part of the SQL INSERT statement even if you set a value because of the insertable = false.

    But its not working as expected. Am I doing anything wrong here?

    What is not working exactly? Can you show the DDL script for the table? What DML INSERT statement is performed exactly? Does Oracle set the default appropriately? Don’t you get it back in the entity after the insert? When does it fail?

    Just in case, aren’t you missing a Temporal annotation on the creationTime? According to the JPA 1.0 spec:

    9.1.20 Temporal Annotation

    The Temporal annotation must be specified for persistent fields or properties of type
    java.util.Date and java.util.Calendar. It may only be specified for fields or properties of these types.

    I would add a @Temporal(TemporalType.DATE).

    Not sure this will solve the issue though but answering the above questions might help to diagnose the issue.


    I want Hibernate to set the default value when ever I’m trying to insert. The table i’ve shown is a dummy table which I created for testing/learnig purpose. The Original table is a legacy one and it does not have the ‘DEFAULT’ attribute set. Sorry about the confusion.

    The columnDefinition element of the Column annotation is used to specify the SQL fragment that is used when generating the DDL for the column, that’s all. If you don’t use the JPA provider to generate the DDL and if your table doesn’t have any DEFAULT defined, nothing will happen.

    So in your case, I would probably use a lifecyle callback and set the date if null during PrePersist:

    @Entity
    public class Account {
        ...
    
        @PrePersist
        protected void setCreationDateIfRequired() {
            if (getCreationDate() == null) {
                setCreationDate(...);
            }
        }
    
    }
    

    Reference

    • JPA 1.0 Specification
      • Section 3.5.1 “Lifecycle Callback Methods”
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.