add <property name="hibernate.hbm2ddl.auto" value="create-drop"/> to hibernate property this will re-create table when SessionFactory init, drop table when session factory close
prepare meta data, and insert the meta data into MemDB, now I use @Before annotation from Junit, so I need to test if we need to insert the data indead, because the method annotated by @Before will be executed each time for test method
@Before
public void prepareData() throws ServiceException {
if($needPrePareData){
executeSqlFile("init_data.sql");
}
}
private void executeSqlFile(String fileName){
try{
File refFile = new File(ClassLoader.getSystemResource(fileName).toURI());
SqlFile sqlFile = new SqlFile(refFile,false,null);
sqlFile.execute(dataSource.getConnection(), true);
}catch(Exception e){
System.out.println("exception when prepare Data ");
e.printStackTrace();
}
}