Hibernate import.sql Tip

本文介绍Hibernate提供的自动导入数据功能,通过在classpath下创建import.sql文件,并设置hibernate.hbm2ddl.auto属性为create或create-drop,可以实现在创建SessionFactory时自动执行SQL脚本导入数据。值得注意的是,import.sql中的每条SQL语句必须独占一行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值