Rotterdam JBug and Hibernate's import.sql

Posted by    |      

The Rotterdam JBug is happening June 20th and import.sql is a pretty neat feature for unit testing. Two unrelated infos in one entry today, let's call it macroblogging!

Rotterdam JBug on June 20th

The Benelux JBoss User Group is organizing an event on Friday June 20th 2008. There will be plenty of presentations:

  • JBoss Portal - Julien Viet and Thomas Heute - JBoss
  • Hibernate Search - Emmanuel Bernard - JBoss
  • Woman in IT - (special guest presentation) Clara Ko and Linda van der Pal -
  • JBoss Drools - Kris Verlaenen - JBoss

Here is more information, it's free of course but you need to register.

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 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.

Back to top