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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:34:29+00:00 2026-05-25T11:34:29+00:00

Assume that in a database table there is a non-key column called RECORD_ID which

  • 0

Assume that in a database table there is a non-key column called RECORD_ID which is auto-generated/sequenced in database.

Now in my entity for the table above, just above the field for RECORD_ID, I use the hibernate annotation @Generated to indicate to hibernate that DB will take responsibility for inserting value into that particular field. It looks like the following:

@Column(name = "RECORD_ID", unique = true, nullable = true, insertable = false, updatable =  false)
    @Generated(GenerationTime.INSERT)
    private Long recordId;

I run my code and it works fine. DB is inserting value as expected.

Now, I write a unit-test case with HSQL to ensure my logic is intact.
The logic has a query which fetches the record based on RECORD_ID.

Now when i create fixture and invoke my test, HSQL will not generate value for the record’s RECORD_ID when I save my fixture. It leaves it as null. But the logic that I intend to test is based on fetching by RECORD_ID which isn’t possible here.

It just remains null in HSQL DB. And hence I am not able to complete unit testing!

Kindly throw some light on solving this issue or any workaround.

Please find the unit-test code below

@Test
public void testProductCancelDAL() {
    savePrerequisites();
    Logic myLogic = new Logic();
    /* Logic fetches the reservation record based on RECORD_ID */
    assertNotNull(myLogic.invoke());

}
public void savePrerequisites() {
    //Stroing product type
    Product product = ProductFixture.createProduct();
    sessionFactory.getCurrentSession().save(product);

    //Storing Itinerary
    Itinerary itn = ItnFixture.create();
    sessionFactory.getCurrentSession().save(itn);

    Reservation res = ReservationFixture.create();
    sessionFactory.getCurrentSession().save(res);
    sessionFactory.getCurrentSession().flush();
}
  • 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-25T11:34:30+00:00Added an answer on May 25, 2026 at 11:34 am

    Based on what you said in the comments, it appears that you’re testing some code which depends on a trigger in the database generating the RECORD_ID, but that you test this on an in-memory database where this trigger doesn’t exist. This, obviously, won’t work. You need to create the same trigger as in your production database. See http://hsqldb.org/doc/2.0/guide/triggers-chapt.html to create triggers in a HSQLDB database.

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

Sidebar

Related Questions

Assume that the database connection is good, the table name and column name are
I have a database table called users This table has two columns (that are
I have a mysql database that stores some timestamps. Let's assume that all there
Assume that you have a running SQL Server Express instance named (local)\SQLEXPRESS. Its database
Assume that I want to listen to a non-common port (9090 for example) 24/7
Here is something that troubles me as I am creating a database table columns.
I am writing a standard database-backed business application. Assume that I work with bank
I have the following tables in my database that have a many-to-many relationship, which
I have a database table that i want to allow my friends to update.
Assume that there is application that must interact with a DB of more than

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.