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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:34:33+00:00 2026-05-16T06:34:33+00:00

I have a Spring/Hibernate webapp that has some integration tests that run on an

  • 0

I have a Spring/Hibernate webapp that has some integration tests that run on an in-memory HSQL database. Hibernate takes this blank database and creates all of my test tables and constraints thanks to hbm2ddl=create. However, I have a new bean that checks for a particular config value from the database during its afterPropertiesSet() method, and so when this bean is initialized, such a row needs to exist in the database.

Is there any good way to set up a Java/Spring/Hibernate equivalent of Rail’s test fixtures? I’m trying to find a way to tell Hibernate “whenever you create this table, insert these rows immediately afterwards”. I couldn’t find a callback or a hook I could add, but maybe there’s another way.

  • 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-16T06:34:34+00:00Added an answer on May 16, 2026 at 6:34 am

    I’m trying to find a way to tell Hibernate “whenever you create this table, insert these rows immediately afterwards”

    Since Hibernate 3.1, you can include a file called import.sql in the runtime classpath of Hibernate and at the time of schema export, Hibernate will execute the SQL statements contained in that file after the schema has been exported.

    This feature has been announced in the Rotterdam JBug and Hibernate’s import.sql blog post:

    import.sql: easily import data in your unit tests

    Hibernate has a neat little feature
    that is heavily under-documented and
    unknown. You can execute an SQL script
    during the SessionFactory creation
    right after the database schema
    generation to import data in a fresh
    database. You just need to add a file
    named import.sql in your classpath
    root and set either create or
    create-drop as your
    hibernate.hbm2ddl.auto property.

    I use it for Hibernate Search in
    Action now that I have started the
    query chapter. It initializes my
    database with a fresh set of data for
    my unit tests. JBoss Seam also uses it
    a lot in the various examples.
    import.sql is a very simple feature
    but is quite useful at time. Remember
    that the SQL might be dependent on
    your database (ah portability!).

    #import.sql file
    delete from PRODUCTS
    insert into PRODUCTS (PROD_ID, ASIN, TITLE, PRICE, IMAGE_URL, DESCRIPTION) values ('1', '630522577X', 'My Fair Lady', 19.98, '630522577X.jpg', 'My Fair blah blah...');
    insert into PRODUCTS (PROD_ID, ASIN, TITLE, PRICE, IMAGE_URL, DESCRIPTION) values ('2', 'B00003CXCD', 'Roman Holiday ', 12.98, 'B00003CXCD.jpg', 'We could argue that blah blah');
    

    For more information about this
    feature, check Eyal’s blog, he
    wrote a nice little entry about it.
    Remember if you want to add additional
    database objects (indexes, tables and
    so on), you can also use the auxiliary
    database objects feature.

    It is still not really documented.

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

Sidebar

Related Questions

I'm writing Integration tests for a webapp using Spring AbstractJUnit tests and Hibernate for
I am coming from a Spring/hibernate background. I have noticed that Rails has no
We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
Is it possible to define a spring-managed EJB3 hibernate listener? I have this definition
We use Spring + Hibernate for a Webapp. This Webapp will be deployed on
Hey I am developing an desktop application using Spring and Hibernate, and I have
I'm using Hibernate with Spring in my application. I have been consistently using detached
I have a JSP that is using Spring:form tags to bind controls to a
They say that a closed session in hibernate and webapp with ajax is a
I've been wondering lately. Lets say we're doing a webapp with JSF+Spring+JPA/Hibernate (or well

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.