習慣Spring + Hibernate帶來的方便, 但有時在應(yīng)用中測試Hibernate的新功能并不是很方便.
實際上Hibernate的test代碼就有這個功能, 而且不用考慮create table等麻煩事.
在自己的project中使用, 只需繼承org.hibernate.test.TestCase, 改變hand code的路徑, 設(shè)定hibernate.properties文件, 這樣就有了純Hibernate測試環(huán)境
public abstract class HibernateTestCase extends TestCase


{
protected HibernateTestCase(String x)

{
super(x);
}


protected String getBaseForMappings()
{
return "com/waterye/test/";
}


/**//**
* true時, 使用auto schema export, hibernate.hbm2ddl.auto create-drop
*/

protected boolean recreateSchema()
{
return false;
}
}
說明: 以idea為例
1. 將hibernate.properties放到test根目錄下
2. pojo, hbm.xml, Test.java放到同一目錄下(參考hibernate的測試代碼)
3. 在idea中run test method