Hibernate 配置详解(12) 其实我也不想用这么土的名字
hibernate.hbm2ddl.import_files
这个配置用于在hibernate根据映射文件执行DDL之前,如果我们自己设置了要事先运行的SQL文件,hibernate就会先执行这些SQL文件。比如,在classpath下面任意创建一个SQL文件:ddl.sql,然后添加:
public static InputStream getResourceAsStream(String resource) { String stripped = resource.startsWith("/") ? resource.substring(1) : resource; InputStream stream = null; ClassLoader classLoader = ClassLoaderHelper.getContextClassLoader(); if (classLoader!=null) { stream = classLoader.getResourceAsStream( stripped ); } if ( stream == null ) { stream = Environment.class.getResourceAsStream( resource ); } if ( stream == null ) { stream = Environment.class.getClassLoader().getResourceAsStream( stripped ); } if ( stream == null ) { throw new HibernateException( resource + " not found" ); } return stream; }
5,默认情况下,放在SQL文件中的SQL语句,只能是一条SQL一行,不能格式化的。
再说说看代码的心情,其实有的时候看别人的代码可以发现其实还是会有一些小瑕疵可以博得一笑,有兴趣的可以看看hibernate.hbm2ddl.import_files这个配置的加载过程。还有时候可以看到别人代码上面的注释,有的也是挺有爱的。