Hibernate import.sql Tip

xiaoxiao2026-05-21  14

[size=medium]Hibernate的一个小功能对开发人员的单元测试挺有用的:在创建SessionFactory对象的时候[color=red]自动导入数据(import.sql)[/color]. 大家应该都很熟悉,在classpath下面建一个import.sql语句,还有把hibernate.hbm2ddl.auto属性设置为create或create-drop即可,不过我今天最主要的是说两个步骤都做了,但还以能成功导入数据的问题,就是我们在import.sql中的SQL语句,[color=red]一行必须是一个完整的SQL语句[/color],否则就可能导入数据失败.[/size] [size=medium] [color=red]hibernate + import.sql[/color] This is my first article in my blog, it just a tip. As we know, Hibernate has a function of import data automatically and it's useful for the unit test. We can execute our SQL script where we getting SessionFactory. step 1:create a file named import.sql in the classpath; step 2:set the hibernate.hbm2ddl.auto property value of creat or create-drop. (notice: [color=red]one line one SQL script[/color], and this is why I write on my blog)[/size]
转载请注明原文地址: https://www.6miu.com/read-5049126.html

最新回复(0)